Open passalini opened 8 years ago
I'll throw in a "me too" on this: running into the same problem with a custom tag I've got.
+1
+1
Solution:
Variables that must change for each forloop should not be @instance
variables. Instead, set these in the render
method (or thereafter) as temporary variables (e.g. var
not @var
).
Explanation:
As far as I can tell, initialize
is called only once at the start of a forloop, and the whole class remains alive for the duration of that forloop. Thus, any instance variable carries its values from loop to loop.
Guys, I'm working with a code that gave me an strange behaviour. For example, I have a liquid's post view that renders many comments and its edit's forms, those comments are inside a snippet with a custom tag
form
.In this custom tag, the code initialize the @form_type that is used to define the form's path and other things.
Now, the strange thing! This tag works properly outside the
for
loop, but in thefor
theinitialize
function is called just once and therender
function is called correctly (x loop times). The problem with it is that in the second time all instance variables defined in the custom tag arenil
. With this behaviour theform_by_type
function does not return anything and the final htmlform
will be withoutaction
,class
,id
.....Let me show you some example code:
I can do this work putting the instance variables initialization inside the
render
function, but I want to know if is right do this and if it have some bad implications. Or if this code have something wrong that are causing this behaviour.Thanks...