Skip to content

Implement ifchanged Liquid tag - #910

Merged
sebastienros merged 1 commit into
mainfrom
sebros/ifchanged
Jan 21, 2026
Merged

Implement ifchanged Liquid tag#910
sebastienros merged 1 commit into
mainfrom
sebros/ifchanged

Conversation

@sebastienros

Copy link
Copy Markdown
Owner

Summary

Implements the {% ifchanged %} Liquid tag, which outputs content only when it has changed from the previous invocation.

Changes

  • Fluid/Ast/IfChangedStatement.cs - New AST node that:

    • Renders inner statements to a buffer
    • Compares with the previous output stored in context.AmbientValues
    • Only outputs content if it differs from the last ifchanged output
  • Fluid/FluidParser.cs - Registers the ifchanged/endifchanged block tag

  • Fluid/Ast/AstVisitor.cs & AstRewriter.cs - Added visitor methods

  • Fluid.Tests/GoldendLiquidTests.cs - Enabled golden liquid tests (removed skip entry)

  • Fluid.Tests/IfChangedStatementTests.cs - 9 new unit tests

Behavior

All {% ifchanged %} blocks share a single "previous value" in the render context. This matches Shopify Liquid's behavior:

{% assign foo = 'hello' %}
{% ifchanged %}{{ foo }}{% endifchanged %}  {# outputs 'hello' #}
{% ifchanged %}{{ foo }}{% endifchanged %}  {# no output (unchanged) #}
{% assign foo = 'goodbye' %}
{% ifchanged %}{{ foo }}{% endifchanged %}  {# outputs 'goodbye' #}

Common use case - grouping in loops:

{% for item in list | sort %}
  {% ifchanged %}{{ item }}{% endifchanged %}
{% endfor %}

Tests

  • All 5 golden liquid tests for ifchanged tag pass
  • 9 new unit tests pass
  • All 2415 existing tests pass (20 skipped for unrelated features)

- Add IfChangedStatement AST node that renders content only when it changes
- Register ifchanged/endifchanged block tag in FluidParser
- Add visitor methods to AstVisitor and AstRewriter
- Enable golden liquid tests for ifchanged tag (5 tests)
- Add 9 unit tests in IfChangedStatementTests.cs
@sebastienros
sebastienros merged commit 23783a3 into main Jan 21, 2026
3 checks passed
@sebastienros
sebastienros deleted the sebros/ifchanged branch January 21, 2026 16:16
@hishamco

Copy link
Copy Markdown
Collaborator

Is this an offical tag by Shopify?

@sebastienros

Copy link
Copy Markdown
Owner Author

@hishamco

Copy link
Copy Markdown
Collaborator

Are there any missing tags or filters, I need to put my hands dirty again in Fluid :) It has been awhile

@sebastienros

Copy link
Copy Markdown
Owner Author

AFAIK everything is implemented, that's why I added Golden Test Suite

There are a few skipped tests but mostly because implementing these things could be complex or too expensive for such niche feature. You can always check in the open issues though is there is something intereseting.

sebastienros added a commit that referenced this pull request Aug 20, 2026
- Add IfChangedStatement AST node that renders content only when it changes
- Register ifchanged/endifchanged block tag in FluidParser
- Add visitor methods to AstVisitor and AstRewriter
- Enable golden liquid tests for ifchanged tag (5 tests)
- Add 9 unit tests in IfChangedStatementTests.cs

Co-authored-by: GitHub Copilot CLI <copilot@github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ee9c8775-0354-41dd-8226-89a69c60241c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants