Brad Padgett
Well-known member
Okay I have a simple question. The below code may seem complicated but the only part I want you to pay attention to is the <a><img></a> tags.
I want to run a foreach block for the <a> link tag but exclude the image from it where it only displays once. I have been at this for a week so if you could take a moment to help me it would be worth it. Normally I would just take the image out of the foreach block but in this case the functionality is inside the link so this is impossible.
@Sim was kind enough to suggest I don't use <xf:foreach> but this seems to be the easiest way as the code I was working with prior did not work. This code actually functions correctly but repeats the image 5 times. Each image links to the appropriate link but I want it all inside a single image. I really appreciate your help. I would have used another method but this seems to be the best way as I have a hunch there is a simple way to escape a <xf:foreach> for a nested tag that I'm just not seeing or found.
I want to run a foreach block for the <a> link tag but exclude the image from it where it only displays once. I have been at this for a week so if you could take a moment to help me it would be worth it. Normally I would just take the image out of the foreach block but in this case the functionality is inside the link so this is impossible.
@Sim was kind enough to suggest I don't use <xf:foreach> but this seems to be the easiest way as the code I was working with prior did not work. This code actually functions correctly but repeats the image 5 times. Each image links to the appropriate link but I want it all inside a single image. I really appreciate your help. I would have used another method but this seems to be the best way as I have a hunch there is a simple way to escape a <xf:foreach> for a nested tag that I'm just not seeing or found.
HTML:
<xf:if is="property('LightSwitch_On') == 'Enabled'">
<xf:set var="$dark" value="{{ [ property('Dark_Switch'), property('Dark_Switch2'), property('Dark_Switch3'), property('Dark_Switch4'), property('Dark_Switch5')] }}" />
<xf:set var="$image" value="{{ base_url('styles/default/BP/LightSwitch/bulb-off.png', true) }}" />
<xf:if is="property('styleType') == 'light'">
<xf:foreach loop="$dark" key="$key" value="$style" i="$i">
<div style="float: left;">
<a href="{{ link('misc/style', null, {'style_id': $style,'_xfRedirect': $xf.fullUri,'t': csrf_token()}) }}">
<img src="{$image}" alt="turn the lights off">
</a>
</div>
</xf:foreach>
</xf:if>
<xf:set var="$light" value="{{ [ property('Light_Switch'), property('Light_Switch2'), property('Light_Switch3'), property('Light_Switch4'), property('Light_Switch5')] }}" />
<xf:set var="$image" value="{{ base_url('styles/default/BP/LightSwitch/bulb-on.png', true) }}" />
<xf:if is="property('styleType') == 'dark'">
<xf:foreach loop="$light" key="$key" value="$style" i="$i">
<div style="float: left;">
<a href="{{ link('misc/style', null, {'style_id': $style,'_xfRedirect': $xf.fullUri,'t': csrf_token()}) }}">
<img src="{$image}" alt="turn the lights on">
</a>
</div>
</xf:foreach>
</xf:if>
</xf:if>