 |
Smarty
The discussions here are for Smarty, a template engine for the PHP programming language. Dedicated server web hosting provided by Guru-host.eu. |
| View previous topic :: View next topic |
| Author |
Message |
ileansolutions Smarty n00b
Joined: 26 Mar 2012 Posts: 3
|
Posted: Mon Mar 26, 2012 6:56 pm Post subject: Inserting an {if} inside another {if} doesn't work |
|
|
Hello all, I am trying to display two (2) field items into a page using the following code, but its not working... I don't know if it has anything to do with an {if} statement inside another... not sure if this is even possible
| Code: | {if $field->name == 'drawings'}
<div id="{$name}">Download DWG Drawing: <a href="{$entry->file_location}/{$field->value}">{$field->value}</a><br/></div>
{* * * PDF DRAWING * * *}
{if $field->name == 'pdf_drawing'}
<div id="{$name}">Download PDF Drawing: <a href="{$entry->file_location}/{$field->value}">{$field->value}</a></div>
{/if}
{/if}
any suggestions/ideas? Thank you :?: |
|
|
| Back to top |
|
ileansolutions Smarty n00b
Joined: 26 Mar 2012 Posts: 3
|
Posted: Mon Mar 26, 2012 7:27 pm Post subject: SOLVED |
|
|
So I was able to solve this by passing just calling the parameter separately as someone had mention I could do (i.e. I am not a programmer, so I had a hard time figuring this one out). Here is my final working code. By the way, would you have done it differently?
| Code: | {if $field->name == 'drawings'}
<div id="{$name}">
{* * * DWG DRAWING * * *}
<div id="dwgdra">Download DWG Drawing: <a href="{$entry->file_location}/{$field->value}">{$field->value}</a><br/></div>
{* * * PDF DRAWING * * *}
<div id="pdfdra">Download PDF Drawing: <a href="{$entry->file_location}/{$entry->fields.pdf_drawing->value}">{$entry->fields.pdf_drawing->value}</a></div>
</div>
{/if} |
|
|
| Back to top |
|
tsudeki Smarty Rookie

Joined: 22 Mar 2006 Posts: 13
|
Posted: Thu Mar 29, 2012 10:04 pm Post subject: Re: Inserting an {if} inside another {if} doesn't work |
|
|
| ileansolutions wrote: | Hello all, I am trying to display two (2) field items into a page using the following code, but its not working... I don't know if it has anything to do with an {if} statement inside another... not sure if this is even possible
| Code: | {if $field->name == 'drawings'}
<div id="{$name}">Download DWG Drawing: <a href="{$entry->file_location}/{$field->value}">{$field->value}</a><br/></div>
{* * * PDF DRAWING * * *}
{if $field->name == 'pdf_drawing'}
<div id="{$name}">Download PDF Drawing: <a href="{$entry->file_location}/{$field->value}">{$field->value}</a></div>
{/if}
{/if}
any suggestions/ideas? Thank you :?: |
|
I know that you've resolved this so that it works for you, but it may be helpful to explain why it didn't work before. The outer {if} is evaluating the $field->name value. If it's "drawings" then the stuff inside the {if} happens.
Then, from within that {if} you're evaluating $field->name again to see if it equals "pdf_drawing" which we already know to be false because the first {if} only triggers if $field->name is equal to "drawings."
If you're only wanting to display the one that exists (either a "drawing" or a "pdf_drawing") you'll need to do an {elseif} instead of a nested {if} like so:
| Code: | {if $field->name == 'drawings'}
<div id="{$name}">Download DWG Drawing: <a href="{$entry->file_location}/{$field->value}">{$field->value}</a><br/></div>
{* * * PDF DRAWING * * *}
{elseif $field->name == 'pdf_drawing'}
<div id="{$name}">Download PDF Drawing: <a href="{$entry->file_location}/{$field->value}">{$field->value}</a></div>
{/if} |
|
|
| Back to top |
|
ileansolutions Smarty n00b
Joined: 26 Mar 2012 Posts: 3
|
Posted: Thu Mar 29, 2012 10:19 pm Post subject: Thanks |
|
|
Thank you for explaining, I am not a programmer so I can't explain in too much detail what the process is, I was able to figure it out with the help of a developer on another forum.
Thank you for explaining the elseif alternative, I want to go back and try this so that I learn something new. Thanks again! |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|