-
Notifications
You must be signed in to change notification settings - Fork 110
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
Importing Jet Template does not bring Variables #107
Comments
Can you try include instead of import?
Import is used for making block definitions available for use, include evaluates the templates.
… On Oct 17, 2018, at 10:25 PM, JesseRyan ***@***.***> wrote:
Consider the following:
Params.jet ->
{{ param1 := 1 }}
{{ param2 := 2 }}
{{ param3 := 3 }}
{{ param4 := 4 }}
then import Params.jet in another template.
SomeJetTemplate.jet ->
{{ import "Params.jet" }}
{{ "This is a string needing to use parameters : " + param1 }}
This throws a block level scope failure that param1 does not exist in the scope of the block...
Is there a way to load parameter configurations like this into other jet templates? Seems like this should work...
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Did that help? |
Hey thank you for attention again, Unfortunately this did not work. Is this intended to work? Do you have a working example? It would be really great if this would work. |
having the same issue, +1 for feature request. |
found a work around; {{ var = value }} seems to declare with global scope |
You have to pass data as third parameter like this,
Example, Main Html Template Partial Template |
You don't need to declare in global scope. |
That was actually a bug and fixed in 16fe512, so this won't work as a "workaround" anymore. I'll look into importing variables as well was blocks, but I'm not sure it's something you'd want. Would you expect a variable "foo" from an imported template to overwrite a variable "foo" in your current template scope? |
@sauerbraten actually, in some cases this would be quite handy. Imagine you have set of templates that should be able to derive the same set of variables/attributes from what was provided to them. For example:
In this situation, it would be most useful to be able to include a template which contains the common logic and provides metadata to other templates. Imagine it as a subroutine. Workaround:
This solution is "good from far", but far from good, I am afraid. But in my case it works. Please note that I am posting this only to show that the case for this functionality is probably there, not to offer any solution. Example use casePlease not that the example uses custom delimiters. Consumer of the "common" logic
Provider of the "common" logic" (trf_commons.jet)PLease note that this is a contrived and incomplete example. But it shows the idea.
Snippet of code
|
It sounds like you could use Have a base template defining all the "global" vars you want, then make different "consuming" templates that extend from it. Since code outside of blocks doesn't run in the "consumer" (extending) templates, you'd have to define something like a Would this not solve the problem you're having? |
Consider the following:
then import Params.jet in another template.
This throws a block level scope failure that param1 does not exist in the scope of the block...
Is there a way to load parameter configurations like this into other jet templates? Seems like this should work...
I do of course understand that parameters can be added to vars and imported into templates from compiled go code. However, we would like to remain dynamic and maintain the essence of Jet templates in that we could change the text i.e. the parameters on the fly without having to recompile go code.
The text was updated successfully, but these errors were encountered: