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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add do tag to allow calling functions/macros and not having output #165
Add do tag to allow calling functions/macros and not having output #165
Conversation
The do tag does the same thing as a using regular template tags (`{{ ... }}`); except it doesn't output anything. This is useful if you have a function or macro that has verbose output or side effects, but you don鈥檛 want to display output.
@@ -953,7 +954,6 @@ impl<'a> Parser<'a> { | |||
Ok(ast::FromImport { expr, names }) | |||
} | |||
|
|||
#[cfg(feature = "macros")] |
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 functions can be called via do, this needed to be removed. Thoughts?
expect_token!(self, Token::BlockEnd(..), "end of block"); | ||
|
||
// End of block may not exist, for example with do block. | ||
if let Some((Token::BlockEnd(..), _)) = ok!(self.stream.current()) { |
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.
I'm not sure if this is the best way to check, or would lead to user confusion.
If they are using enddo, it will error anyway.
Ugh not sure what happened here. I did not intend on closing this. |
Ah I see. The merge base was my now deleted call block branch so this auto closed this PR as well. Can your rebase this off main? I'm in favor of adding this. |
Yep, seems rebasing should be fine, just doing that now. As you said, I had based this off the other branch, where deleting it closes this. Hopefully, I can rebase and it'll work. |
Based off this conversation: #83
Happy to discuss if this should be merged. Moreover, happy for this to be tweaked/reworked to make it in the best possible state. 馃殌
I also initially named this DoBlock, but IMHO it's confusing to name that as someone might think they could use it the same way they would the
call
tag.What is a do tag?
The do tag does the same thing as a using regular template tags (
{{ ... }}
); except it doesn't output anything.This is useful if you have a function or macro that has verbose output or side effects, but you want to avoid displaying output.
Reasoning
The reasoning for adding this is that this is super handy when working with projects that use jinja2 extensively, like dbt, where it's quite useful.
Example (from dbt-utils readme).
(I know you know most/all of this, but the explanation is for everyone else, and when I forget :D )