Re: [SMARTY-DEV] Block/Section (in trad. sense) function needed?
| From: | Peter Bowyer | Date: | Sat, 04 May 2002 11:22:06 +0000 |
| Subject: | Re: [SMARTY-DEV] Block/Section (in trad. sense) function needed? | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-77@lists.php.net to get a copy of this message | ||
Hi,
Just another example I came across in my work today :-)
Currently for Smarty I have the following in one of my templates (this is only a small section of it):
{if $data[i].fax}
<strong>Fax: </strong> {$data[i].fax}
{/if}
{if $data[i].email}
<strong>Email: </strong><a href="mailto:{$data[i].email}">{$data[i].email}</a>{/if} Now, wouldn't it be a lot cleaner with the traditional style of block as proposed in my last email? The designer no longer has to worry whether $data[i].xx is set or not: {block name="fax"}
<strong>Fax: </strong> {$data[i].fax}
{/block}
{block name=email}
<strong>Email: </strong><a href="mailto:{$data[i].email}">{$data[i].email}</a>{/block} And now it is up to the programmer to check if the element of the array is empty and if so to delete the block, which provides a bit more separation of the design from the logic. I'm not sure how this example could be implemented as the code above is inside a {section} so I think it's possibly impossible, as there's no way to get Smarty to remember for which iteration not to show these blocks. I have however posted it to hopefully give ideas of how Smarty can be made more designer friendly, and separate more strongly the logic and presentation. Regards, Peter. --oOo-- Narrow Gauge on the web - photos, directory and forums! http://www.narrow-gauge.co.uk --oOo-- Glenbranter - Scottish narrow gauge in 009 http://glenbranter.narrow-gauge.co.uk --oOo--