-
-
Notifications
You must be signed in to change notification settings - Fork 187
Support combining with/as and named arguments in render tag #832
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
Conversation
…rtial fix Co-authored-by: sebastienros <[email protected]>
…nation Co-authored-by: sebastienros <[email protected]>
|
|
||
| var options = new TemplateOptions() { FileProvider = fileProvider, MemberAccessStrategy = UnsafeMemberAccessStrategy.Instance }; | ||
| var context = new TemplateContext(options); | ||
| _parser.TryParse("{% render 'snippet', class: 'test' %}{{ class }}", out var template); |
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.
| _parser.TryParse("{% render 'snippet', class: 'test' %}{{ class }}", out var template); | |
| _parser.TryParse("{% render 'snippet', class: 'test' %}", out var template); |
I suppose we don't want {{ class }} here as it's not what we're checking for and leads to doubling output
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 think this test is actually checking that this is not available in the calling template, check the name of the test. And also the result (no dupliation)
Co-authored-by: Mikhail Savelev <[email protected]>
Summary
Fixes the parser to allow combining
with/asorfor/assyntax with named arguments in therendertag, matching Shopify Liquid's behavior.Problem
Previously, Fluid only accepted either the
with/assyntax or named arguments, but not both together. This was inconsistent with Shopify Liquid, where combining them is valid and commonly used:{%- render 'icon' with 'rating-star', class: 'rating__star' -%}Attempting to parse this template resulted in:
Changes
1. Parser Enhancement (
FluidParser.cs)Modified the
RenderTagparser to accept optional named arguments afterwith/asandfor/asexpressions:Reordered parser alternatives to check
with/forbefore named-arguments-only to ensure correct precedence.2. Statement Execution Fix (
RenderStatement.cs)Fixed a critical bug in the if/else branch order. When both
ForandAssignStatementswere present, the code incorrectly took the assign-only branch instead of the for branch:Added support for evaluating assign statements within both
withandforbranches while maintaining proper scope isolation.3. Comprehensive Tests (
IncludeStatementTests.cs)Added 6 new tests covering all combinations:
with+ named argumentswith+as+ named argumentswith+ multiple named argumentsfor+ named argumentsfor+as+ named argumentsExamples Now Supported
{%- render 'icon' with 'rating-star', class: 'rating__star' -%} {% render 'product' with my_product as p, price: '$99' %} {% render 'button' with 'Click Me', size: 'large', color: 'blue' %} {% render 'product' for products, tag: 'sale' %} {% render 'item' for items as i, status: 'active' %} {% render 'collection-product-list' with c, limit_count: 2, heading_text: 'All Products' %}Testing
Fixes #[issue_number]
Original prompt
Fixes #830
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.