Welcome Guest, Not a member yet? Register   Sign In
Parser fails when iterating through data twice slightly differently
#1

[eluser]MrAzulay[/eluser]
Found what appears to be a bug (can't possibly see what I do wrong) in the parser of CodeIgniter.

Doesn't work:

Code:
<ul>
    {categories}
        <li>{title}[{id}] - <i>{description}</i></li>
        <ul>
        {children}
            <li>{subTitle}[{subId}] - <i>{subDescription}</i></li>
        {/children}
        </ul>
    {/categories}
</ul>
&lt;form acti&gt;
    &lt;input type="text" placeholder="Title"&gt;
    &lt;input type="text" placeholder="Description"&gt;

    <select>
        {categories}
            <option>
                {title}
            </option>
        {/categories}
    </select>

    &lt;input type="submit" value="+"&gt;
&lt;/form&gt;
The parser works fine for the first iteration creating list elements. Further down though where I create the select dropdown the parser wont parse and i just get this output

Code:
<select>
    {categories}
        <option>
            {title}</i></li>
        </option>
    {/categories}
</select>
The strange thing is if i copy the code for the list output and run that twice it works fine and the parser gives me two ul lists.

Works fine:

Code:
<ul>
    {categories}
        <li>{title}[{id}] - <i>{description}</i></li>
        <ul>
        {children}
            <li>{subTitle}[{subId}] - <i>{subDescription}</i></li>
        {/children}
        </ul>
    {/categories}
</ul>
<ul>
    {categories}
        <li>{title}[{id}] - <i>{description}</i></li>
        <ul>
        {children}
            <li>{subTitle}[{subId}] - <i>{subDescription}</i></li>
        {/children}
        </ul>
    {/categories}
</ul>
But as soon as i change one little character in the second iteration it breaks. So it seems like you can only iterate the same data if the "html" is the same around the variables.

What is going on here?
#2

[eluser]InsiteFX[/eluser]
Give the second one a different name, categories1 categories2 etc;

Open up ./system/Parser.php and look at the code.
#3

[eluser]MrAzulay[/eluser]
[quote author="InsiteFX" date="1360507337"]Give the second one a different name, categories1 categories2 etc;

Open up ./system/Parser.php and look at the code.
[/quote]

Thanks InsiteFX, I think I see the problem. Kinda bothering to pass the same data twice though as it doesn't make much sense from the views perspective (and neither from the controller). Would be great with a fix for this or if anyone have any other suggestion.
#4

[eluser]Aken[/eluser]
Not difficult to add, if someone wants to have a go: https://github.com/EllisLab/CodeIgniter/issues/2237
#5

[eluser]MrAzulay[/eluser]
https://github.com/EllisLab/CodeIgniter/pull/2238

I gave it a shot, seems to work fine




Theme © iAndrew 2016 - Forum software by © MyBB