Answers for "set variable in twig"

0

twig set variable

{% set foo = 'bar' %}
Posted by: Guest on May-14-2021
3

twig is set variable

{# defined works with variable names #}
{% if foo is defined %}
    ...
{% endif %}

{# and attributes on variables names #}
{% if foo.bar is defined %}
    ...
{% endif %}

{% if foo['bar'] is defined %}
    ...
{% endif %}
Posted by: Guest on February-11-2020
0

twig set variable

{% set foo = 'bar' %}			{# string #}
{% set foo = 12 %}				{# integer #}
{% set foo = [1, 2] %} 			{# array #}
{% set foo = {'foo': 'bar'} %} 	{# objet #}
Posted by: Guest on September-29-2021
0

modele de twig html : payant

<?php
// menu.php
// inclure  l'autoloader
include 'vendor/autoload.php';

try {
    // le dossier ou on trouve les templates
    $loader = new TwigLoaderFilesystemLoader('templates');

    // initialiser l'environement Twig
    $twig = new TwigEnvironment($loader);

    // load template
    $template = $twig->load('Menu.html');

    // set template variables
    // render template
    echo $template->render(array(
        'lundi' => 'Steak Frites',
        'mardi' => 'Raviolis',
        'mercredi' => 'Pot au Feu',
        'jeudi' => 'Couscous',
        'vendredi' => 'Poisson',
    ));

} catch (Exception $e) {
    die ('ERROR: ' . $e->getMessage());
}
Posted by: Guest on October-11-2020

Browse Popular Code Answers by Language