Skip to content
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

Example using a {% do return(...) %} statement in a Jinja macro #5247

Merged
merged 8 commits into from
Apr 10, 2024

Conversation

dbeatty10
Copy link
Contributor

@dbeatty10 dbeatty10 commented Apr 8, 2024

Preview

What are you changing in this pull request and why?

There's a subtle difference between these two:

  • {{ return([1,2,3]) }} (an expression that outputs a string)
  • {% do return([1,2,3]) %} (a statement that does not output a string)

This PR adds an example of using the do tag along with the return function.

More detail

The "do" extension (AKA expression-statements) adds a simple do tag to the template engine that works like a variable expression but ignores the return value.

Put another way, there is a difference between expressions and statements in Jinja:

  • Expressions {{ ... }}: Expressions are used when you want to output a string. You can use expressions to reference variables and call macros.
  • Statements {% ... %}: Statements don't output a string. They are used for control flow, for example, to set up for loops and if statements, to set or modify variables, or to define macros.

Checklist

  • Review the Content style guide so my content adheres to these guidelines.
  • I've verified that the code example works

Copy link

vercel bot commented Apr 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-getdbt-com ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 10, 2024 6:22am

@github-actions github-actions bot added content Improvements or additions to content size: small This change will take 1 to 2 days to address labels Apr 8, 2024
@dbeatty10 dbeatty10 marked this pull request as ready for review April 8, 2024 19:37
@dbeatty10 dbeatty10 requested a review from a team as a code owner April 8, 2024 19:37
@dbeatty10 dbeatty10 changed the title Example using do tag (AKA expression-statement) that doesn't output a string Example using a {% do return(...) %} statement in a Jinja macro Apr 8, 2024
add diff ways to use return function
@mirnawong1
Copy link
Contributor

hey @dbeatty10 , looks awesome and made some suggested changes. would love your input!

@dbeatty10 dbeatty10 enabled auto-merge (squash) April 9, 2024 20:50
@dbeatty10
Copy link
Contributor Author

Thanks for your suggestions @mirnawong1 -- I committed them, and they really improved it overall.

Ready for another review.

@dbeatty10 dbeatty10 merged commit 2f3b450 into current Apr 10, 2024
11 checks passed
@dbeatty10 dbeatty10 deleted the dbeatty10-patch-2 branch April 10, 2024 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Improvements or additions to content size: small This change will take 1 to 2 days to address
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants