Surge-ee / SurgerEE

A collection of simple tags for expressionengine that make template development easier.
Mozilla Public License 2.0
37 stars 8 forks source link

Selective parsing of modulo in (sub)template #8

Closed richplane closed 12 years ago

richplane commented 12 years ago

Here's a funny one for you.

This useage, as per your example -

{exp:channel:entries dynamic="no"}
    {if '{exp:surgeree:modulo numerator="{count}" denominator="2"}' == 1}<div class="section">{/if}
<h3>{title}</h3>
    {if '{exp:surgeree:modulo numerator="{count}" denominator="2"}' == 0}</div>{/if} 
{/exp:channel:entries}

(a massively simplified version of a subtemplate I'm using)

produces:

    <h3>Title 1</h3>
                    </div>
    <h3>Title 2</h3>
                    </div>
    <h3>Title 3</h3>
                    </div>
    <h3>Title 4</h3>
                    </div>
    <h3>Title 5</h3>
                    </div>
etc...

Probably the latter since

{exp:channel:entries dynamic="no"}{count}
    {if '{exp:surgeree:modulo numerator="{count}" denominator="2"}' == 1}<div class="section">{/if}
<h3>{title}</h3>
    {if '{exp:surgeree:modulo numerator="{count}" denominator="2"}' == 0}</div>{/if} 
{/exp:channel:entries}

will fix the problem.

Any idea why?

I've one hypothesis: EE doesn't spot the use of {count} in the surgeree tag, so doesn't bother running the code to replace {count} with the value. That's a wild stab in the dark. It's the sort of foible that we learn to love and/or lose hair over when using EE.

Can modulo be made to work here? Simple workaround to put {count} in an HTML comment, of course.

robsonsobral commented 12 years ago

Rich, did you try to set the parse attribute to "inward" on surgeree tag? Could you test this, please?

richplane commented 12 years ago

Thanks for the response. I tried this. Changing first line to

{exp:channel:entries dynamic="no" parse="inward"}

makes no difference.

BTW I'm using EE v2.5.2, Structure v3.3.3 (and Structure Entries v1.2.8), and Surgeree 1.5.3.

robsonsobral commented 12 years ago

No, no. Please try to add the parse parameter to the surgeree tag.

richplane commented 12 years ago

oh! That can go on the {exp:surgeree:modulo} tag too can it?

{exp:channel:entries dynamic="no"}
    {if '{exp:surgeree:modulo numerator="{count}" denominator="2" parse="inward"}' == 1}<div class="section">{/if}
...

... makes no difference. Putting {count} in there fixes it again.

robsonsobral commented 12 years ago

I made some tests, rich. You're right. Looks like eecms doesn't parse channel:entries variables inside plugin parameters. I don't know if this is a bug or a deliberated behavior.

For a similar situation, I had to use an embed.

EpocSquadron commented 12 years ago

Confirmed. Not much we can do about this one in the plugin itself.

richplane commented 12 years ago

OK - thanks for this. Just to highlight the workaround I mentioned above, this makes it work:

{exp:channel:entries dynamic="no"}<!--{count}-->
    {if '{exp:surgeree:modulo numerator="{count}" denominator="2"}' == 1}<div class="section">{/if}
<h3>{title}</h3>
    {if '{exp:surgeree:modulo numerator="{count}" denominator="2"}' == 0}</div>{/if} 
{/exp:channel:entries}

Any other inclusion of the variable in the template does seem to make EE parse the variable into the plugin parameters.