Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't pass variables to twig template #7

Closed
ekafyi opened this issue Jul 10, 2015 · 2 comments
Closed

Can't pass variables to twig template #7

ekafyi opened this issue Jul 10, 2015 · 2 comments

Comments

@ekafyi
Copy link

ekafyi commented Jul 10, 2015

According to Twigpress doc and sprig-dir/inc/twigpress.php, you can pass variables to the template with twigpress_render_twig_template($vals = array(), $template = false, $echo = true).

I'm trying to pass variables to the template with the following code but it doesn't work. What am I doing wrong?

single.php:

$vals = array( 'foo' => 'bar' );
twigpress_render_twig_template($vals);

single.twig:

{{ vals.foo }} # Does not print anything #
{{ foo }} # Same #
{{ dump(vals) }} # Prints 'null' #

Please enlighten a n00b! Thanks. :)

@frankinedinburgh
Copy link

Look for the function
render_template($template, $vals)
in class-twigpress.php
/inc/Twig/class-twigpress.php
and add your variables there

eg.
vals = array(
'wp' => self::$twig_proxy,
'my_var' => 'This is my first variable'
);

Then in your twig template you can say {{ my_var }} and it will echo out the value above;

@ekafyi
Copy link
Author

ekafyi commented Nov 17, 2015

Thank you! I have since used non-Sprig related workaround for this project but I'll give it a try next time.

@ekafyi ekafyi closed this as completed Nov 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants