Add if/else Extra Field to showlistings.tpl

Discussion in 'Customizations' started by skyblue, Mar 27, 2010.

  1. skyblue Customer

    Using Designer V4.1.9 with the default template

    Hi,

    I have setup parent child extra fields for Location (parent field), State and Country (both child fields).

    The Extra field names and ID’s for each are as follows:

    Location: id 11 (Parent)
    State: id 12 (child)
    Country: id 13 (child)

    I’m trying to ad a single column to the showlistings.tpl to display either the State or the Country and have been unsuccessful using the following code.

    Code:
    {if {get_extra_field id=$entry.id fid=11} $entry.title==" State"}
    <td{if $entry.class<>""} class="{$entry.class}"{/if}>{get_extra_field id=$entry.id fid=12}</td>	
    {else}
    <td{if $entry.class<>""} class="{$entry.class}"{/if}>{get_extra_field id=$entry.id fid=13}</td>
    {/if}
    I think the issue is in the first line however I'm not sure what the correct statement should be. Any help would be much appreciated.

    Thanks
  2. seymourjames All Hands On Deck

  3. skyblue Customer

    Thanks for the response Seymourjames.

    I tried the following code from the link you provided and using capture worked, however the results always returned for {else} in the showlistings.tpl display.
    Code:
    {capture name='loc'}
     {get_extra_field id=$entry.id fid=11}
     {/capture}
     {if $smarty.capture.loc=="United States"}
     <td{if $entry.class<>""} class="{$entry.class}"{/if}>{get_extra_field id=$entry.id fid=12}</td>	
     {else}
     <td{if $entry.class<>""} class="{$entry.class}"{/if}>{get_extra_field id=$entry.id fid=13}</td>
     {/if}
    The parent extra field named Location, id 11, has two values:
    1. United States - sub ID 12
    2. International - sub ID 13

    I’m not a programmer but it seem as though the line {if $smarty.capture.loc=="United States"} is not working thus resulting in the return of {else}.
  4. seymourjames All Hands On Deck

    I would try doing it the other way where you embed the test in a copy of that plugin- see the other thread.
  5. skyblue Customer

    Thanks again Seymourjames. Unfortunately tweaking the suggested plug in to get the desired output is beyond my limited programming skills. I do appreciate you trying to help.

    I did eventually figure out a simpler solution and am posting it here to close this thread.

    Since a user can only select one of the child fields, the unselected field would be blank. I inserted the following code into the template and it seems to be working just fine.

    Code:
    <td{if $entry.class<>""} class="{$entry.class}"{/if}>{get_extra_field id=$entry.id fid=12}{get_extra_field id=$entry.id fid=13}</td>
  6. seymourjames All Hands On Deck

    That will work too in this case. .

Share This Page