-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
parser: update @include
in templates, to work with relative paths & prevent recursive calls
#21943
parser: update @include
in templates, to work with relative paths & prevent recursive calls
#21943
Conversation
Remove personal traces
Correct path for @include! example
Please add a test too. See |
4fba05d
to
e3a1104
Compare
I was looking into this again and have a few changes which I did not push yet. I got thrown when making additional tests and found that the test templates where in a folder which was named 'tmpl' instead of 'templates'. The logic I originally put down was to search for the 'templates' folder which is only applicable to vweb/veb programs. I was currently looking into using the p.template_paths so that any included template would be relative to it's calling template. That may remove the need to have an extra directive completely. The alternative was to have the root folder named in the @include line so it is easy to find but the syntax could start to get a little verbose |
…go relative to initial template
120be08
to
808ae6a
Compare
This PR is a rethink on the original PR. When an Furthermore there was a bug in the code for circular references. If a template called itself or one of its children called it again then it would result in a circular reference that would crash the program. Now all called templates are entered into a dependency tree which will check if a circular reference exists and will fail with error message should one be encountered. Finally all called templates are put in a temporary cache which will be used instead of costly IO operations if a template is reused in the code. This should benefit complex web applications were templates may represent web components and could be used many times in the app. Note: The original idea of |
@include
in templates, to work with relative paths & prevent recursive calls
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.
Excellent work. It makes the @include
directive a lot more usable, while it improves the error handling too.
@medvednikov what do you think?
Sounds good to me. |
Thanks for the consideration and advice. Hopefully I can help out more in time to come |
Allows calling a partial template directly especially if the partial was previously included as part of a root template. Reasoning added to discussion #21868
TLDR;
Using
@include!
will reference the template relative to the base template directory i.e.templates
folder. Normal action is to include it relative to the template being called. Allows the partial to be called from any other template within the templates directory and its nested directories.