What solution is better and recommended for short string elements? To define block and let user override it contents like:
<title>{% block title %}{% endblock %}</title>
or make block of variables, set their default values and let user import this block reset variable he want like:
base template:
{% block variables %}
{% set meta.title = '' %}
{% endblock %}
<title>{{ meta.title }}</title>
user template:
{% block variables %}
{{ parent() }}
{% set meta.title = 'some title' %}
{% endblock %}
Blocks are used for inheritance and act as placeholders and replacements at the same time. They are documented in detail in the documentation for the extends tag. Block names must consist of alphanumeric characters, and underscores. The first char can't be a digit and dashes are not permitted.
Templates in Symfony are created with Twig: a flexible, fast, and secure template engine.
Twig is the template engine used in Symfony applications. There are tens of default filters and functions defined by Twig, but Symfony also defines some filters, functions and tags to integrate the various Symfony components with Twig templates.
I'd go with blocks. Also, remember that if you want to output contents of a block more than once, you can use the block
function:
<title>{% block title %}{% endblock %}</title>
<h1>{{ block('title') }}</h1>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With