Imagine I have something like this in my twig template
{% block posLeft %} ----- {%endblock%}
Is there any way to check for existance of the posLeft block without calling to:
block("posLeft")
And check the return value of the posBlock to varify the existance. I am a newbie in Symfony2 + Twig.
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.
should check whether the variable is null or empty. If you want to see if it's not null or empty just use the not operator. See the docs: empty.
You can get the current URL in Twig/Silex 2 like this: global. request. attributes. get('_route') .
You can solve it like this, if you want to display a certain block only if it has content. Hope, this is what you're looking for.
Example index.html.twig
{% set _block = block('dynamic') %} {% if _block is not empty %} {{ _block|raw }} {% endif %}
Example part.html.twig
{% extends "index.html.twig" %} {% block dynamic %} Block content goes here. {% endblock %}
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