2015-08-22, 08:33 AM
MyBB 2.0 is using the Twig templating engine rather than the current system of basic PHP templates. Twig offers a lot more functionality, such as built in support for conditional "if" statements, loops, including other templates and more. Twig was chosen for its clean syntax, readability and high level of usage (it is used in hundreds of other projects, meaning it's fairly easy to learn and many people already understand it).
Some examples
To give a brief introduction to how Twig works, here are a few samples of templates from the 2.0 core. This should give you a taste of the syntax, but we highly recommend reading the "Twig for template designers" guide if you are a theme designer.
This template is used to render the usernames of users who have liked a post. It makes use of loops, condditional statements and functions (such as "trans", which translates a language variable).
Providing feedback
Due to how much work has been done, it is highly unlikely that we will be changing template engine away from Twig. We made the choice to use Twig after evaluating several other options (such as Blade, Smarty, and pure PHP).
Some examples
To give a brief introduction to how Twig works, here are a few samples of templates from the 2.0 core. This should give you a taste of the syntax, but we highly recommend reading the "Twig for template designers" guide if you are a theme designer.
<div class="likes">
<span class="likes__prefix">
<i class="fa fa-caret-{{ langDir.right }}"></i>
</span>
{% for key, like in likes %}
<span class="likes__like" data-like-id="{{ like.id }}">
{% if like.user.name != trans('likes.current_user') %}
<a href="{{ url_route('user.profile', {'slug': like.user.name, 'id': like.user.id}) }}">{{ like.user.name }}</a>
{% else %}
{{ like.user.name }}
{% endif %}
</span>
{% if key < likes|length - 2 or (key == likes|length - 2 and numOtherLikes > 0) %} {# don't show a comma at the end of the list. Key is zero-based, so minus 1. #}
<span class="likes__separator likes__separator--comma">
{{ trans('likes.sep_comma') }}
</span>
{% elseif key == likes|length - 2 %}
<span class="likes__separator likes__separator--and">
{{ trans('likes.sep_and') }}
</span>
{% endif %}
{% endfor %}
{% if numOtherLikes > 0 %}
<span class="likes__separator likes__separator--comma">
{{ trans('likes.sep_and') }}
</span>
<span class="likes__others">
<a href="{{ viewAllLikesLink }}">{{ trans_choice('likes.others', numOtherLikes, {'numOthers': numOtherLikes}) }}</a>
</span>
{% endif %}
{{ trans('likes.like_this') }}
</div>
This template is used to render the usernames of users who have liked a post. It makes use of loops, condditional statements and functions (such as "trans", which translates a language variable).
Providing feedback
Due to how much work has been done, it is highly unlikely that we will be changing template engine away from Twig. We made the choice to use Twig after evaluating several other options (such as Blade, Smarty, and pure PHP).