Re: New custom function

From: Date: Sat, 17 Nov 2001 20:47:04 +0000
Subject: Re: New custom function
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1937@lists.php.net to get a copy of this message
Hello, At 07:14 PM 11/17/01 +0100, Andreas Kossmeier wrote:
how can you use this in real-life and preserve a seperation of functionality and layout? you can't build a table with more complex content like e.g. a basic link or a more complex example under http://www.bergfex.at/soelden/bilder/ or http://www.bergfex.at/tirol/
This is actually possible by using sub-templates. Let me give an example: Suppose I want to put the following into table cells:
            <a href="{$href}">{$label}</a><br>
            {$comment}
I would make myself a template called celldata.tpl containing the above. Now, in my PHP script I would have the following: <?php ... while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
        $smarty->assign("href", $row["href"]);
        $smarty->assign("label", $row["label"]);
        $smarty->assign("comment", $row["comment"]);
        $cells[] = $smarty->fetch("celldata.tpl");
        // I do not know if the following line is needed
        $smarty->clear_assign(array("href", "label", "comment"));
} $smarty->assign("data", $cells); $smarty->display("test.tpl"); ... ?> where test.tpl just contains the {table} tag and any other gubbins needed. This is totally untested, but I think it should work :-)
        {table name=table loop=$data cols=3 table_attr="width=100%"}
            <a href="{$data[table].href}">{$data[table].label}</a><br>
            {$data[table].comment}
        {/table}
that's how i would like to use a table tag/function. but those kind of tags also need a special compiler function.
This would be a much cleaner way to do it, but it isn't possible with the current implementation of Smarty? So I think sub-templates are the best work-around at the present time. Regards, Peter. --oOo-- Narrow Gauge on the web - photos, directory and forums! http://www.narrow-gauge.co.uk --oOo-- Peter's web page - Scottish narrow gauge in 009 http://members.aol.com/reywob/ --oOo--

« previous php.smarty.general (#1937) next »