Re: [SMARTY-DEV] Block/Section (in trad. sense) function needed?
| From: | Andrei Zmievski | Date: | Fri, 03 May 2002 14:07:23 +0000 |
| Subject: | Re: [SMARTY-DEV] Block/Section (in trad. sense) function needed? | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-78@lists.php.net to get a copy of this message | ||
On Sat, 04 May 2002, Peter Bowyer wrote:
> 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.
So?
{section name="fax" show="$fax_show"}
<strong>Fax: </strong> {$data[i].fax}
{/section}
{section name="email" show="$email_show"}
<strong>Email: </strong><a href="mailto:{$data[i].email}">{$data[i].email}</a>
{/section}
And in php you assign $fax_show and $email_show.
But I still think things like that are better done in templates.
-Andrei