Home » PHP » Twig » Top Twig Template Interview And Answer Part 3

Top Twig Template Interview And Answer Part 3

1. How the ternary operator work in twig template?

{{ admin ? 'Admin' : 'User' }}

2. How the ternary operator work with variable in twig template?

{% set suffix = suffix ?? '' %}

3. How can we check the instance of any class in twig template?

{% if child is instanceof('\\Pimcore\\Model\\Document\\Hardlink') %}
{% endif %}

4. How can we append CSS and Javascript file in header in twig template?

{% do pimcore_head_link().appendStylesheet(asset('static/bootstrap/css/bootstrap.css')) %}
{% do pimcore_head_script().appendFile(asset('static/js/jquery-1.11.0.min.js')) %}

5. How can we check for that document have title in twig template?

{% if document.getTitle() is not empty %}
{% do pimcore_head_title().set(document.getTitle()) %}
{% endif %}

Check Also

Top Twig Template Interview And Answer Part 5

1.How can we loop the array in twig template? {% for item in test %} …

Leave a Reply

Your email address will not be published. Required fields are marked *