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

Is it possible to expose variables without having to reference the "=it" varname? #214

Closed
1mike12 opened this issue Nov 29, 2016 · 3 comments
Labels

Comments

@1mike12
Copy link

1mike12 commented Nov 29, 2016

I know we can change the varname to another string, but coming from other template engines like angular or Laravel's blade, the variables are not tied to a global it variable. They exist on the top level scope.

For instance, I want to do this in dot:

bundle

myBundle = {param1: "hello", param2: 42, param3: "salut"};

Template

<div>{{param1}}</div>
<div>{{param2}}</div>
<div>{{param3}}</div>

Is this at all possible? I know it's not a huge deal to type =it everywhere, but it trips me up all the time because the other engines I use don't behave like this.

@epoberezkin
Copy link
Collaborator

epoberezkin commented Nov 29, 2016

The local variables can be used inside template - that's the reason not to use property names without object. Those local variable names are used for iteration, e.g., and can be used for anything. There was an attempt to remove it in the fork: houd1ni@67da310

But it breaks iteration. A more comprehensive attempt would require parsing JavaScript in template and differentiating between local variables and properties of it. It would destroy the main advantage of doT - it's small size and also make template compilation slow. It also would make it difficult to differentiate between it properties and local variables in any even moderately complex template.

@1mike12
Copy link
Author

1mike12 commented Nov 30, 2016

thanks, appreciate the explanation. Would it be helpful to add something relating to this to the readme? I'm sure I'm not the only one to have this thought

@epoberezkin
Copy link
Collaborator

yep, probably. There are quite a few other things to add too. #205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants