optimization - How to optimize the following smarty code so that the iterations performed for comparing array values get reduce? -


I am a newbie for a smart template engine. I am comparing two arrays to my template with a smart template:

= all all_states item = state key = key} {assigned var = "flag" value = false} { $ = Data from foreach.applicable_states Item = pre key = 'index'} {if $ state.id == $ pre} {assign var = "flag" value = true} {$ break} {/ if} {/ foreach } & Lt; Option value = "{$ State.id}" {if $ flag == true} is selected then "selected" {/ if} & gt; {$ State.state_name} & lt; / Options & gt; {/ Foreach}

The above code is working fine for me but if you are not close There is a large number in the number of iterations done in comparison to array values.

Therefore, to reduce the number of iterations, I want to customize the above code. Can someone who can keep a good command on Smerty can provide a way to optimize the above code?

Maybe you are

  {foreach = $ all_states item = state Key = key}. & Lt; Option value = "{$ state.id}" {if $ state.id | In_array: $ data .applicable_states} selected = "selected" {/ if} & gt; {$ State.state_name} & lt; / Options & gt; {/ Foreach}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -