THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline

#1 question debutant smarty

(10-02-2017 12:28:53)


Bonjour,
Dans mon template, j'ai une page ou j'utilise une fonction qui assigne une valeur à une variable.
Comment la rendre global ?

{$variable = 0}
{function mafonction level=0}
...
{$variable = $variable + 10}
...
{/function}
{mafonction param=1}

{$variable}

$variable = 0
elle devrait être égale à 10

Merci

Offline

#2 Re: question debutant smarty

(10-02-2017 16:18:32)


Un peu comme en PHP, les modifications ou créations de variable restent locaux à la fonction, cf http://www.smarty.net/docs/en/language. … nction.tpl

et en particulier :

You can use all variables from the calling template inside the template function. Changes to variables or new created variables inside the template function have local scope and are not visible inside the calling template after the template function is executed.

Par contre, tu peux utiliser le "résultat" (e.g. ce que la fonction écrit) pour faire ça :

{$variable = 0}

{function mafonction level=0}
    ...
    {$variable = $variable + 10}
    {$variable} {* on écrit le resultal *}
{/function}

{* on affecte le resultat écrit à $variable *}
{$variable = {mafonction param=1}}

{$variable} {* ecrit 10 *}


OpenStudio Toulouse

Offline

#3 Re: question debutant smarty

(11-02-2017 13:21:29)


Merci ROADSTER31
je comprends mieux