-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
[Feature request] set context in expressions #73
Comments
I think its a useful feature. +1 for this 👍 I do like the Will it affect on a different context (or may be in this) I was thinking if we can pass an expression to |
I'm ok with
|
I should mention that you can currently trick it into not outputting <!--- {{ title = page.title }} -->
Title is {{ title }} That will output However, I think it's not desirable: doing it inside a comment is not clear for the user whether we want to output this or not. |
Still It would be easy for dev to use set . We can have this feature.. Lets wait for @Scrum for this suggestion |
The offer is great, but here's the first thing that came to mind:
In general, I like the idea, maybe I didn’t have to use it so often, or I didn’t consider its potential |
Honestly I don't really care if we can use |
And then I suddenly thought about {
locals: { page: { title: 'scrum' } },
computed: {
get getPageTitle() {
return this.page && this.page.title ? this.page.title : ''
}
}
} Title is {{ getPageTitle }} Stop me if I started raving)) |
|
Imagine we already had a
page.title
variable in context, and we could access it through{{ page.title }}
. Would be cool if we could define a variable in the context on the fly:{{ title = page.title }} <!-- we can now use {{ title }} instead of {{ page.title }} --> Title is {{ title }}
Currently, that outputs:
Right now, it does kinda work, but it still outputs
undefined
where we've set the variable, as I've explained above.Maybe we could use
const
to identify that we want to set a variable in context:Result:
This would be really useful when you need to access a deeply nested object and you can't use a scope (like inside attributes).
Nunjucks does it with a
set
keyword, they allow you to define a variable like this:If
username
was initially 'James', this would print:What do you think?
The text was updated successfully, but these errors were encountered: