Twig syntax highlighting sublime text

Documentation Syntax highlighting and auto-completion for Twig in Sublime Text 2is possible with : PHP-Twig.tmbundle TWIG Doc “IDEs Integration” : http://twig.sensiolabs.org/doc/templates.html#ides-integration Bundle’s Github : https://github.com/Anomareh/PHP-Twig.tmbundle Bundle’s Documentation : https://sublime.wbond.net/packages/PHP-Twig Download You can clone the project with : git clone https://github.com/Anomareh/PHP-Twig.tmbundle.git Or download it directly from the Github (last master version) : https://github.com/Anomareh/PHP-Twig.tmbundle/archive/master.zip Installation To install … Read more

Updating object properties in twig

Answer from 2013 You can do it by merging objects: {% set object = object|merge({‘property1’: ‘somenewvalue’}) %} Update from 2023 I don’t know from which version of twig this solution does not work anymore. Now you can only create an object with a new name: {% set data = {foo:1} %} {% set updated = … Read more

Twig, add first and last class

You can use the “special variables” loop.first and loop.last for what you want. LINK {% for elem in arrMenu %} {% if loop.first %} <div class=”topmenu-button first”> {% elseif loop.last %} <div class=”topmenu-button last”> {% else %} <div class=”topmenu-button”> {% endif %} <a href=”{{ elem.url }}”>{{ elem.name }}</a> </div> {% endfor %} EDIT: depending how … Read more

Increment value in twig file

Use this: {% set myVal = 50 %} {% for item in items %} {% set myVal = myVal + 10 %} {% endfor %} For declaring, setting values, setting blocks/forms, etc. you must use {% %}. For output, there is {{ }}

Symfony2 – Twig – How can I send parameters to the parent template?

Here is a simple example: base.html.twig: {# base.html.twig #} … <ul> <li{% if menu_selected|default(‘one’) == ‘one’ %} class=”selected”{% endif %}>One</li> <li{% if menu_selected == ‘two’ %} class=”selected”{% endif %}>Two</li> <li{% if menu_selected == ‘three’ %} class=”selected”{% endif %}>Three</li> </ul> … page2.html.twig: {# page2.html.twig #} {% extends ‘YourBundle::base.html.twig’ %} {% set menu_selected = ‘two’ %} Output … Read more

Directly access a form field’s value when overriding widget in a twig template

You can access the current data of your form via form.vars.value: {{ form.vars.value.title }} See Symfony2 Forms documentation: http://symfony.com/doc/current/book/forms.html#rendering-a-form-in-a-template Dump vars by using dump function: {{ dump(form.vars.value) }} If you are using subforms or want to have a value of a specific field: {{ form.FIELD.vars.VALUE }}

Overriding blocks within included Twig templates

I found a solution. Use the block() function to get the child’s block content and pass it to header.html.twig as a variable in the include statement: #base.html.twig {% include ‘elements/header.html.twig’ with {page_title: block(‘page_title’)} %} {% block content %}{% endblock %} {% include ‘elements/footer.html.twig’ %} #header.html.twig <h1>This is my header</h1> {% if page_title is empty %} … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)