Skip to content

Commit a41393f

Browse files
committed
Add param-evaluation-order specs for include vs render
include_params_see_earlier_params (c=200): {% include 't' a: 1, b: a %} → "1-1". Include params accumulate in a temp scope — b sees a. render_params_independent (c=220): {% render 't' a: 1, b: a %} → "1-". Render params are evaluated independently against the outer scope — b does NOT see a (a is undefined in outer scope). Stems from render's isolation: fresh scope per call, params don't cross-reference. Hints cross-reference each other to make the contrast explicit. Verified against liquid-ruby 5.13.
1 parent ea78f19 commit a41393f

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

specs/basics/partials.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,33 @@ specs:
317317
hint: 'Parameters work similarly to render.
318318
319319
'
320+
- name: include_params_see_earlier_params
321+
template: "{% include 't' a: 1, b: a %}"
322+
filesystem:
323+
t: "{{ a }}-{{ b }}"
324+
expected: 1-1
325+
complexity: 200
326+
hint: |
327+
Param evaluation order for include: params are evaluated against a temp
328+
scope that ACCUMULATES earlier params. So `b: a` sees `a: 1` — b resolves
329+
to 1. This is because include shares scope and builds the param scope
330+
incrementally. Contrast with render, where params are evaluated
331+
independently against the outer scope (see render_params_independent).
332+
- name: render_params_independent
333+
template: "{% render 't' a: 1, b: a %}"
334+
filesystem:
335+
t: "{{ a }}-{{ b }}"
336+
expected: 1-
337+
complexity: 220
338+
hint: |
339+
Param evaluation order for render: params are evaluated INDEPENDENTLY
340+
against the outer scope, NOT against each other. So `b: a` looks up `a`
341+
in the outer scope (where it's undefined → empty), even though `a: 1`
342+
is also being passed. Result: a=1, b="" → "1-". This is the opposite of
343+
include, where params accumulate in a temp scope and later params see
344+
earlier ones (see include_params_see_earlier_params). The difference
345+
stems from render's isolation: each render call gets a fresh scope, and
346+
params don't cross-reference each other.
320347
- name: include_sees_outer_variables
321348
template: "{% assign outer = 'visible' %}{% include 'snippet' %}"
322349
filesystem:

0 commit comments

Comments
 (0)