php - How to add variables to Twig -
i want add together values twig object, used when render()/display() template. "assign" function. can find in documentation pass array render()/display().
for example, want flow like:
$twig = makenewtwigetc(); ... ... $twig->assign('error','bad username/password'); ... ... $twig->display('login-form.html'); ... twig template file can output error {{ error }}
your illustration error message not siutable situation, error messages sent flashbags, if want declare global twig variables there ways can do:
inparameters.yml
file set variable - ex, sitename: site name
, in config.yml
file under twig
section -> globals
section set it, for ex:
# twig configuration twig: globals: sitename: "%sitename%"
after can utilize in template files sitename
addglobal()
method, can find more info here php symfony2 templates twig
No comments:
Post a Comment