-
Notifications
You must be signed in to change notification settings - Fork 3
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
exec tag added to enable treating evaluated string as a part of the t… #1
Conversation
There is a typo in description. instead of c2 its c1
|
tags_exec.go
Outdated
} | ||
templateSet := ctx.template.set | ||
s := temp.String() | ||
currentTemplate, err2 := templateSet.FromString(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not need to have differrent name for err. you can use as err instead of err2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue is that err and err2 are of different types.. err is basically pongo2.Error. thats why it is causing type error
tags_exec.go
Outdated
} | ||
templateSet := ctx.template.set | ||
s := temp.String() | ||
currentTemplate, err2 := templateSet.FromString(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentTemplate, err2 := templateSet.FromString(s) | |
tempBytes := temp.Bytes() | |
currentTemplate, err := templateSet.FromBytes(tempBytes) |
Change is because FromString converts string to bytes. Using FromBytes will not do conversion from temp to tempString(temp.String()) and tempString to bytes again(inside FromString)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
#1) * exec tag added to enable treating evaluated string as a part of the template, added tests * added logging and comments * minor change for context creation * fixed tests, incorporated changes from pr * removed unnecessary type conversion Co-authored-by: Surya Prakash <sp@Suryas-MacBook-Pro.local>
#1) * exec tag added to enable treating evaluated string as a part of the template, added tests * added logging and comments * minor change for context creation * fixed tests, incorporated changes from pr * removed unnecessary type conversion Co-authored-by: Surya Prakash <sp@Suryas-MacBook-Pro.local>
…emplate, added tests
Description of the change
Idea is to provide users a functionality so that by using
{% exec %}
templatetag, they can evaluate a string based template (say passed as an argument) as a part of the original template.For example user can define a macro in string and use that in the same execution flow.
Our use case was that user can define macros in yaml and then call it from the yaml itself and we should be able to treat the macro as one of the predefined macros. Earlier we were doing two step evaluation but that limited the capability of the system.
We could not define this templateTag from outside as it has to use few variables private to the package.
some_file.template
so effectively this file will be evaluated as
and the result will be
Type of change
Related issues
Checklists
Development
Code review