You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the (RenderContact.set_local_var)[https://docs.rs/handlebars/2.0.0/handlebars/struct.RenderContext.html#method.set_local_var] which has been drop in the 3.x version
in favor of BlockContext.
BlockContext is really a great things to scope variable properly, I have no doubt with that,
but I have created and use a lot a set filter using the register_helper.
Is theres a way it did not see to keep my set helper with handlebars 3 ?
Here is my use cases:
I am maintaining a REST Client such as POSTMAN, which is not a clickodrome.
It is used to create local variables on top of every templates,
which is a very usefull feature for my project.
Actually
I use handlebars to render HTTP requests, some variables comes from the context,
but local variables are updated in the template.
# List repositories for the given username
{{ set username = "mardiros" }}
POST {{ api_graphql }}
Authorization: bearer {{ token }}
User-Agent: Rustaman
Content-Type: application/json
{
"query": "query { repositoryOwner(login:\"{{ username }}\") { repositories(first: 100, isFork: false, privacy: PUBLIC, orderBy: { field: CREATED_AT, direction: DESC }) { edges { node { name nameWithOwner isFork }}}}}"
}
The text was updated successfully, but these errors were encountered:
mardiros
changed the title
Issue sith set_local_var for creating a filter in 3.0
[question] Issue sith set_local_var for creating a filter in 3.0
Feb 29, 2020
Actually local var in handlebars is designed to carry some contextual data, like index in an iterator. To access local var, you will need to prefix it with @. There was an implementation issue prior to 3 that allows you to access it without @. This has been fixed in 3.0.
So you should be able to fix it by changing {{ username }} to {{ @username }}. But note that local var is only available in current scope. Helpers like each and with will create their own scopes.
But I think handlebars decorator might fit your scenario better. In handlebars-rust, decorator allows to mutate the Context within the remaining render process.
I used the (RenderContact.set_local_var)[https://docs.rs/handlebars/2.0.0/handlebars/struct.RenderContext.html#method.set_local_var] which has been drop in the 3.x version
in favor of
BlockContext
.BlockContext
is really a great things to scope variable properly, I have no doubt with that,but I have created and use a lot a
set
filter using theregister_helper
.https://github.com/mardiros/rustaman/blob/master/src/helpers/handlebars.rs#L8
My question is:
Is theres a way it did not see to keep my
set
helper with handlebars 3 ?Here is my use cases:
I am maintaining a REST Client such as POSTMAN, which is not a clickodrome.
It is used to create local variables on top of every templates,
which is a very usefull feature for my project.
Actually
I use handlebars to render HTTP requests, some variables comes from the context,
but
local variables
are updated in the template.Real word example:
Context
Template:
The text was updated successfully, but these errors were encountered: