Plugin

Archived
Forum
(read-only)

Loop Plugin

ExpressionEngine 1.x, ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From PutYourLightsOn

     

Embed variables in for loop?

Support (Resolved)

Stinkotter
Stinkotter

Hi Ben,

Thanks for creating this simple plugin, works perfectly! I have one question.. I can’t use embed variables within the loop tags (probably because those are seen as tags and not parsed by the plugin).

Example:

{exp:for_loop start="1" end="{number}" increment="1"}
 
<option value="{index}"{if embed:selected == "{index}"} selected{/if}>{index}</option>
{/exp:for_loop} 

embed:selected works fine outside the for_loop tags, but not inside.

Is there a quick workaround for this?
Thanks in advance!

Stinkotter
# 1
Stinkotter

Hmm seemed to find a fix myself, but it’s not so pretty (enabling php).

<?php $selected "{embed:selected}"?>
{exp
:for_loop start="0" end="{niet}" increment="1"}
 
<option value="{index}"<?php if ($selected == "{index}"echo " selected"} ?>>{index}</option>
{/exp:for_loop} 
PutYourLightsOn
# 2
Developer
PutYourLightsOn

seems like an embed within a loop would be terrible for performance, does a snippet work?

Stinkotter
# 3
Stinkotter

Hi Ben,

I’m not really embedding a template within the loop, just reading an embed variable, which I passed to the loop. Seems fast enough, there are no additional queries or any noticeable downgrade in time.

My mistake by the way, didn’t have the code in the first post within code tags, so some code was missing.
Guess I’ll stick with this solution (enabling php) for now.

Thanks for your reply

PutYourLightsOn
# 4
Developer
PutYourLightsOn

ah yes i see. good to hear it’s not hurting performance.