V
V
viktorross2019-05-15 05:01:42
Smarty
viktorross, 2019-05-15 05:01:42

Problem with smarty loop?

Hello, there was a problem that I didn’t notice right away, there are several fields, when choosing 1 field everything is fine, value 1 is 1. But after selecting field 1, field 2 appears dependent on it, in which the value 1 will already be the second in the list, and the first value is a link generated to whatever is selected in the previous field. Thus in the second field the last value leaves as 1 value of the third dependent field.
It is not clear why such confusion occurred .. here is the template

{* ---------------- depending field 1 ------------------ *}
  <h3 class="heading"><span class="fgsd_Tyr">{$v.depending.name1}</span></h3>
  {if !isset($post_array[$v.depending.caption1]) || !$post_array[$v.depending.caption1]} {* no value set *}
  <select class="tests45" style="width: 100%;" onchange="window.location.href=this.options[this.selectedIndex].value">
<option value="">{$lng.search.no_selectedrefine}</option>
  {foreach from=$v.depending.elements item=t name=elements}
    {capture name=field_string assign=field_string}{$v.depending.caption1}-{$t.name|lower|replace:'/':'_'}/{/capture}
    
    <option value="{if $settings.enable_locations && in_array($v.depending.caption1, $location_fields)}javascript:;" onclick="changeLocation('{$live_site}', '{$v.depending.caption1}|{$t.name|rawurlencode}'){else}{if $seo_settings.enable_mod_rewrite}{$constructed_url|replace:$sfield:$field_string}{else}{$constructed_url}{$separator}{$v.depending.caption1}={$t.name|replace:'/':'_'}{/if}{/if}">{$t.name|truncate:19:"...":true}</option>

    
  {/foreach}
  
  </select>

  {else} {* a value is set for this field *}

  <div class="property current-filter" style="text-transform: capitalize; font-weight: 700;">{$post_array[$v.depending.caption1]}<div class="rfloat"><a href="{if $settings.enable_locations && in_array($v.depending.caption1, $location_fields)}javascript:;" onclick="changeLocation('{$live_site}', '{$v.depending.caption1}|'){else}{$constructed_url|replace:$sfield:''}{/if}" class="remove"><i class="fa fa-trash fa-lg" style="vertical-align:bottom; margin-right:10px; padding-bottom:2px; color:#09f;"></i></a></div></div>

  {/if}

  <hr/>

  {* ---------------- depending field 2 ------------------ *}
  {if isset($post_array[$v.depending.caption1]) && $post_array[$v.depending.caption1]}
  <h3 class="heading"><span class="fgsd_Tyr">{$v.depending.name2}</span></h3>
  {if $seo_settings.enable_mod_rewrite}{assign var="separator" value="?"}{else}{assign var="separator" value="&amp;"}{/if}

  {if $seo_settings.enable_mod_rewrite}
    {capture name=sfield assign=sfield}##{$v.depending.caption2}##/{/capture}

    {seo->makeSearchLink p1=$post_array p2=$page p3="page|category|`$v.depending.caption2`|`$v.depending.caption3`|`$v.depending.caption4`" p4=$v.depending.caption2  p5=$category_name assign='constructed_url'}

  {else}

    {capture name=some_content assign=constructed_url}{$live_site}/listings.php?page=1{foreach from=$post_array key=k item=x name=construct_url}{if $x!='' && $k!=$v.depending.caption2 && $k!=$v.depending.caption3 && $k!=$v.depending.caption4 && $k!="page" && $k!="show" && (!$settings.enable_locations || (!in_array($k, $location_fields) && $k!="crt_city"))}{$separator}{$k}={$x|replace:'/':'_'}{assign var="separator" value="&amp;"}{/if}{/foreach}{/capture}

  {/if}
    
      {if !isset($post_array[$v.depending.caption2]) || !$post_array[$v.depending.caption2]}
    
    <select class="tests45" style="width: 100%;" onchange="window.location.href=this.options[this.selectedIndex].value">
        <option value="">{$lng.search.no_selectedrefine}</option>
      {foreach from=$v.depending.elements2 item=t name=elements2}
    <option value="{if $settings.enable_locations && in_array($v.depending.caption2, $location_fields)}javascript:;" onclick="changeLocation('{$live_site}', '{$v.depending.caption2}|{$t.name|rawurlencode}'){else}{if $seo_settings.enable_mod_rewrite}{$constructed_url|replace:$sfield:$field_string}{else}{$constructed_url}{$separator}{$v.depending.caption2}={$t.name|replace:'/':'_'|rawurlencode}{/if}{/if}">{$t.name|truncate:19:"...":true}</option>
    {capture name=field_string assign=field_string}{$v.depending.caption2}-{$t.name|lower|replace:'/':'_'|rawurlencode}/{/capture}
      {/foreach}
</select>

  {else} {* a value is set for this field *}

  <div class="property current-filter" style="text-transform: capitalize; font-weight: 700;">{$post_array[$v.depending.caption2]}<div class="rfloat"><a href="{if $settings.enable_locations && in_array($v.depending.caption2, $location_fields)}javascript:;" onclick="changeLocation('{$live_site}', '{$v.depending.caption2}|'){else}{$constructed_url|replace:$sfield:''}{/if}" class="remove"><i class="fa fa-trash fa-lg" style="vertical-align:bottom; margin-right:10px; padding-bottom:2px; color:#09f;"></i></a></div></div>

  {/if}

  <hr/>
  {/if} 
{* ---------------- end depending field 2 ------------------ *}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question