-
-
Notifications
You must be signed in to change notification settings - Fork 10k
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
variables in include tag with filters #1789
Conversation
Looks great:exclamation: A few questions:
|
Thanks for your feedback! I readjusted the regex which does the parsing. Now arbitary whitespace may be used inside the variable. Something like this should be possbile: http://rubular.com/r/SqZ9BbyNNl I changed the error messages, because
Example error message with I think the 2nd error message is more informative. What do you think? Filtering literals like I will add some tests! |
|
if /\{\{([\w\-\.]+)\}\}/ =~ @file | ||
raise ArgumentError.new("No variable #{$1} was found in include tag") if context[$1].nil? | ||
context[$1] | ||
if /(?<variable>\{\{\s*(?<name>[\w\-\.]+)\s*(\|.*)?\}\})(?<params>.*)/ =~ @file |
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.
As you're using the same regex twice, you might want to move it to a constant, like VALID_SYNTAX
above.
I wouldn't worry about working around the named group problem. |
Fixed by merge of #1841. |
Use variable {% include %} with filters
This pull request adds support for filters when using the include tag with a variable.
To be more precise:
Since PR #1495 it is possible to use variables inside an include tag, like that:
but unfortunately you cannot use filters.
With this pull reuqest you can use something like this:
This is especially useful when you want to modify the file/filename which should get included.
Possible use cases
Append
.html
to the file nameMake sure the file name is lowercase
Prepend a directory to choose another directory inside the
_includes/
directory