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

Get variables from template #329

Closed
ArmorDarks opened this issue Nov 29, 2014 · 2 comments
Closed

Get variables from template #329

ArmorDarks opened this issue Nov 29, 2014 · 2 comments

Comments

@ArmorDarks
Copy link

Hi

Sorry for quite newbie question.

Is there a way to get variables from template?

For example, I have index.nj template

{% set myVariable = "Variable value" %}

myVariable value is: {{ myVariable }}

What I need is to get myVariable from template before compiling it.

In other words, something like:

var nunjucks = require('nunjucks');

var env = nunjucks.configure('templates/');
var tmpl = env.getTemplate('index.nj')

// Now I need to get value of variable `myVariable` from template, like `tmpl.getVariables();`
// to process it afterward

... compilation stuff ...

Thanks in advance for any help

@mkoryak
Copy link

mkoryak commented Dec 4, 2014

This goes against MVC - the view consumes the model, not the other way around.
Your templates should consume data provided to them from the controllers. If you need to go the other way, you are doing it wrong.

@carljm
Copy link
Contributor

carljm commented Dec 4, 2014

@mkoryak is right. This is not something nunjucks needs to support.

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

3 participants