Announcement

Collapse
No announcement yet.

Conditional using array?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Conditional using array?

    Could somone help me with refining this "brute force" set of conditionals? I'm sure that there must be a more elegant solution, probably using an array, but that's as far as I get!

    Code:
    <if condition="$show['reputation'] AND $post['reputationlevelid']==16">Credibility: <img src="$stylevar[imgdir_reputation]/-3.gif" alt="$post[username] $post[level]" border="0"></if>
    <if condition="$show['reputation'] AND $post['reputationlevelid']==17">Credibility: <img src="$stylevar[imgdir_reputation]/-2.gif" alt="$post[username] $post[level]" border="0" /></if>
    <if condition="$show['reputation'] AND $post['reputationlevelid']==18">Credibility: <img src="$stylevar[imgdir_reputation]/-1.gif" alt="$post[username] $post[level]" border="0" /></if>
    <if condition="$show['reputation'] AND $post['reputationlevelid']==19">Credibility: <img src="$stylevar[imgdir_reputation]/0.gif" alt="$post[username] $post[level]" border="0" /></if>
    <if condition="$show['reputation'] AND $post['reputationlevelid']==20">Credibility: <img src="$stylevar[imgdir_reputation]/1.gif" alt="$post[username] $post[level]" border="0" /></if>
    <if condition="$show['reputation'] AND $post['reputationlevelid']==24">Credibility: <img src="$stylevar[imgdir_reputation]/2.gif" alt="$post[username] $post[level]" border="0" /></if>
    <if condition="$show['reputation'] AND $post['reputationlevelid']==21">Credibility: <img src="$stylevar[imgdir_reputation]/3.gif" alt="$post[username] $post[level]" border="0" /></if>
    <if condition="$show['reputation'] AND $post['reputationlevelid']==22">Credibility: <img src="$stylevar[imgdir_reputation]/4.gif" alt="$post[username] $post[level]" border="0" /></if>
    <if condition="$show['reputation'] AND $post['reputationlevelid']==23">Credibility: <img src="$stylevar[imgdir_reputation]/5.gif" alt="$post[username] $post[level]" border="0" /></if>
    Thanks!

    John

  • #2
    You might want to read up on: Online manual > Using PHP Functions in Template Conditionals

    Comment


    • #3
      One way to clean up code like that is to use the value of the variable to call the img src, like this:

      Code:
      <if condition="$show['reputation'] AND $post['reputationlevelid']">
      
      Credibility: <img src="$stylevar[imgdir_reputation]/[color=red]$post[reputationlevelid][/color].gif" alt="$post[username] $post[level]" border="0">
      
      </if>
      This works if the variable values match up to your image names.

      Comment

      Loading...
      Working...
      X