Re: [SMARTY-DEV] Block/Section (in trad. sense) function needed?

From: Date: Mon, 06 May 2002 14:27:35 +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-79@lists.php.net to get a copy of this message
You can already do this block functionality with sections. {section name=foo loop=1 show=$show_foo} ... {/section} The programmer would set $show_foo depending on whether or not that section (block) should show. This is also more powerful than a plain {block ...} function because you have all the power of {section ...} at your disposal. This also cures your problem of blocks within sections ;-) Monte 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} &nbsp;
{/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} &nbsp;
{/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--
-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.

« previous php.smarty.dev (#79) next »