mardi 22 mai 2018

How to get random values with twig including same file multiple times

I'm trying to figure out, how to include one template multiple times with different random values.

I do have a template:

<div class="include-1">
  Liquid error: This liquid context does not allow includes.
</div>
<div class="include-2">
  Liquid error: This liquid context does not allow includes.
</div>
<div class="include-3">
  Liquid error: This liquid context does not allow includes.
</div>

Inside the include.twig I have:

<span>
  
</span>

Expected result (numbers in span should be random in range from 0–10):

<div class="include-1">
  <span>1</span>
</div>
<div class="include-2">
  <span>2</span>
</div>
<div class="include-3">
  <span>3</span>
</div>

Actual result (the first include get the random value, but then it is just "cached"):

<div class="include-1">
  <span>1</span>
</div>
<div class="include-2">
  <span>1</span>
</div>
<div class="include-3">
  <span>1</span>
</div>

I've tested include, embed etc. but with no avail. I'm looking for a twig based solution. Cannot touch PHP. As a fallback I can do it with JS, but was interested if such a thing can be done it Twig.

Question:

Is there a way how to force Twig to re-render the include before each include?




Aucun commentaire:

Enregistrer un commentaire