Questions tagged [twig]

Twig is a modern, fast, flexible, and secure templating engine for PHP. Created for Symfony and adopted by Drupal 8.

Twig is a modern template engine for . It is developed for, and used by default, in the , , and frameworks, but can also easily be used in other projects. It’s both designer and developer friendly by sticking to PHP’s principles and adding functionality useful for templating environments.

Its key features are (source: https://twig.symfony.com/) :

  • Fast: Twig compiles templates down to plain optimized PHP code. The overhead compared to regular PHP code was reduced to the very minimum.
  • Secure: Twig has a sandbox mode to evaluate untrusted template code. This allows Twig to be used as a template language for applications where users may modify the template design.
  • Flexible: Twig is powered by a flexible lexer and parser. This allows the developer to define its own custom tags and filters, and create its own DSL.

When asking or answering a question, do not hesitate to isolate the problematic code to reproduce it or solve it in an external environment, such as twigfiddle, to get more efficient help or give a working solution.

For more details refer to:

  1. Official Website
  2. Twig Documentation
  3. Twig Installation
  4. Twig Download from Github
10606 questions
3
votes
1 answer

Including Js in twig template

I am trying to build a simple contacts app using Backbone js to learn backbone.I am using symphony to serve the page.But i am not able to include the app.js file in my twig template.Here are my files : index.html.twig {% extends 'base.html.twig'…
user3437315
  • 270
  • 4
  • 13
3
votes
1 answer

Why is the Symfony2 profiler throwing 404s when using the MemcachedProfilerStorage?

I'm struggling to identify the cause of 404's when using the Symfony2 profiler. I'm using Symfony 2.3 LTS. I have the profiler enabled on our development environments and the issue is reproducible across several developer machines. Our configuration…
edhgoose
  • 887
  • 8
  • 26
3
votes
1 answer

How can I order my table's columns using a keyword?

My column is currently {article, formation , tous article , tous formation, notif, offre}. I want to make it in this order {article, tous articles , espace , formation , tous formation ,  , notif , offre} This is my code, the td is named:…
user3070123
  • 159
  • 2
  • 20
3
votes
1 answer

SlickGrid - Handling DataView with grid.onAddNewRow

I am using SlickGrid to generate a data grid. The data is fetched by a jQuery AJAX call. With the advice from https://stackoverflow.com/a/11611477/2294855 I am able to handle the response data and set it to the DataView. But my problem arises when I…
Stiff Roy
  • 31
  • 4
3
votes
0 answers

Weird Timezone Issues with Symfony2/Twig

I am trying to figure out a weird issue with timezones when displaying a datetime with Twig in a Symfony2 application, and have a couple of questions about what I am seeing on one of my Twig templates when trying to display datetimes. First,…
Daryl Gubler
  • 305
  • 2
  • 14
3
votes
2 answers

Symfony2 form: Money Currency Symbol and Displaying in Twig

I've got a form in Symfony that uses the money field type with the currency set to GBP. When I pass the form over to twig the form is rendered using: {{ form_row(form.price) }} This renders the following html: £
Liam Sorsby
  • 2,912
  • 3
  • 28
  • 51
3
votes
1 answer

Twig use specific value for 0 results, 1 result and multiple results

While working on an article module in Symfony2, I have to display how many times something is read. To make the 'sentence' grammatically correct I used the code below. This works obvious but it botters me that I can't find a shorter, cleaner way. Is…
Stefan
  • 1,248
  • 6
  • 23
3
votes
2 answers

Extending Twig's AppVariable

I've inherited a website that uses Symfony 2. The site was working fine until I ran composer to upgrade packages. It upgraded Symfony 2.6 to 2.7.1 and Twig 1.18 to 1.18.2. I now get the following error: Method "site" for object…
Anthony
  • 12,177
  • 9
  • 69
  • 105
3
votes
2 answers

symfony twig render dynamic twig code

In my symfony2 action, i have: $twigCode = '
  • {{ data.value }}
  • '; //In database $datas = array(array( 'value' => 'line 1'), array( 'value' => 'line 2')); return $this->render( '...List.html.twig', array( 'twigCode' =>…
    Harold
    • 669
    • 1
    • 7
    • 31
    3
    votes
    6 answers

    Twig Error after Symfony 2.7 Upgrade: "The "native_profiler" extension is not enabled

    After A Symfony Upgrade, composer.json "symfony/symfony": "2.4.*", "symfony/symfony": "2.7.*", I get a Error while running phpunit tests. In env dev and prod everything works fine. log output: request.CRITICAL: Uncaught PHP Exception…
    ToBe
    • 86
    • 4
    3
    votes
    2 answers

    Where has the Twig function 'render' in templates gone?

    I have just updated my dependencies for my Silex application and now suddenly one of my templates is failing with the error: Twig_Error_Syntax: The function "render" does not exist. This was working fine before I performed a composer update. From…
    Russell Seymour
    • 1,333
    • 1
    • 16
    • 35
    3
    votes
    2 answers

    Raw twig variable filter within a short if

    I am using short conditional to discriminate the values ​​displayed in a list of records. For example if I want the name of the customers who have a greater than 100 identifier are emphasized ( ) perform the following: {# Displays the…
    JSGarcia
    • 556
    • 7
    • 18
    3
    votes
    0 answers

    How to enable Twig syntax for HTML/PHP files in PhpStorm?

    I'm having trouble getting Twig syntax checking and highlighting for *.php and *.tpl* files in PhpStorm? It throws a lot of syntax errors. The HTML and PHP syntax is already getting picked up. In Settings | File Types | Twig, I can't add filetype…
    Bas Peeters
    • 3,269
    • 4
    • 33
    • 49
    3
    votes
    1 answer

    Multiple Twig_Extension in Symfony2

    I want to register my custom Twig filters in separate bundle (to avoid having one huge file). I have Yaml configurations in each bundle: # services.yml services: twig.extension.[BundleName]: class: Kuba\[BundleName]\Twig\AppExtension …
    kuba
    • 3,670
    • 3
    • 31
    • 41
    3
    votes
    1 answer

    Wordpress Advanced Custom Field Plugin + Twig template

    I'm creating a real estate website with the template Realia. This theme is based on Twig files and here's my problem. I have a front end submission where we can add a custom post ( a property ). I want to add a custom field to this form. The code…
    Feyrisa
    • 48
    • 8