This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/resources/views/yuuno/macros.twig
2016-12-21 20:55:17 +01:00

50 lines
3 KiB
Twig

{% macro news_post(post, display_title, display_comments, display_category) %}
{% if display_title|default(false) %}
<a href="{{ route('news.post', post.id) }}" class="news__head" id="p{{ post.id }}">{{ post.title }}</a>
{% endif %}
<div class="news__body">
<a class="news__poster" href="{{ route('user.profile', post.user.id) }}">
<div class="avatar avatar--border news__avatar" style="background-image: url('{{ route('user.avatar', post.user.id) }}')"></div>
<div class="news__username" style="color: {{ post.user.colour }}; text-shadow: 0 0 7px {% if post.user.colour != 'inherit' %}{{ post.user.colour }}{% else %}#222{% endif %}">
{{ post.user.username }}
</div>
</a>
<div class="bbcode">
{{ post.text|raw }}
</div>
</div>
<div class="clear"></div>
<div class="news__date">
Posted <time class="time-ago" datetime="{{ post.created.format('c') }}">{{ post.created.format(config('general.date_format')) }}</time>
{% if display_comments|default(false) %}<a href="{{ route('news.post', post.id) }}#comments">{{ post.commentCount }} comment{% if post.commentCount != 1 %}s{% endif %}</a>{% endif %}
{% if display_category|default(false) %}in <a href="{{ route('news.category', post.category.id) }}">{{ post.category.name }}</a>{% endif %}
</div>
{% endmacro %}
{% macro pagination(url, pages, current, class, name) %}
{% set separator %}{% if '%3F' in url|default('')|url_encode %}&amp;{% else %}?{% endif %}{% endset %}
{% set current_page = current|default(1) %}
{% set url = url ~ separator ~ name|default('page') ~ "=" %}
<div class="pagination {{ class }}">
{% if pages is defined and pages|length > 1 %}
{% if current_page > 1 %}
{% if pages|length > 2 %}
<a class="input__button" href="{{ url ~ 1 }}" title="Jump to first page"><span class="fa fa-fast-backward"></span></a>
{% endif %}
<a class="input__button" href="{{ url ~ (current_page - 1) }}" title="Previous page"><span class="fa fa-step-backward"></span></a>
{% endif %}
{% for id,page in pages %}
{% if (id + 1) > (current_page - 3) and (id + 1) < (current_page + 3) %}
<a class="input__button{% if id == current_page - 1 %} input__button--current{% endif %}" href="{{ url ~ (id + 1) }}" title="Page {{ id + 1 }}">{{ id + 1 }}</a>
{% endif %}
{% endfor %}
{% if current_page < pages|length %}
<a class="input__button" href="{{ url ~ (current_page + 1) }}" title="Next page"><span class="fa fa-step-forward"></span></a>
{% if pages|length > 2 %}
<a class="input__button" href="{{ url ~ pages|length }}" title="Jump to last page"><span class="fa fa-fast-forward"></span></a>
{% endif %}
{% endif %}
{% endif %}
</div>
{% endmacro %}