RE: [SMARTY] parsing db content
| From: | Gary Loescher | Date: | Wed, 05 Mar 2003 14:26:28 +0000 |
| Subject: | RE: [SMARTY] parsing db content | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8411@lists.php.net to get a copy of this message | ||
One way to do it would be to eval the contents. It's simple,
but you take a performance hit since everything is recompiled
each time.
A better way is probably to write a resource plugin:
http://smarty.php.net/manual/en/templates.from.elsewhere.php
Store the contents as templates with a timestamp and name,
and then change your top-level relation table to store the
relation between page and template name. Then use {include}
in your foreach.
This way you take advantage of compilation as well as
caching.
HTH,
Gary
>-----Original Message-----
>From: Martin Kloss [mailto:martin.kloss@gmx.de]
>Sent: Wednesday, March 05, 2003 7:46 AM
>To: smarty-general@lists.php.net
>Subject: [SMARTY] parsing db content
>
>
>Hi there,
>
>I'm having a problem filtering tags in content stored in a db.
>Here's what I'm doing:
>
>A db has a table "contents" to store various dynamic contents
>of the site.
>
>A PHP script retrieves the content from the db and assigns
>it to the array variable $contents. That is because in some cases
>there is more than one content on the page.
>
>The template contains the following code to include the contents
>in the page:
>
>{foreach from=$contents item="content"}
> {foreach from=$content item="c"}
> {$c.content}
> {/foreach}
>{/foreach}
>
>Up to this point everything is fine.
>
>NOW, the designers can enter content into the db through a web
>interface.
>What I want him/her to be able to do is include config
>settings like {#font#}
>in the content text, so that the content text is formatted
>according to the
>settings in the config files. BUT of course the content is
>displayed as:
>
>{#font#}This is the content
>
>on the page, since the {} are not parsed.
>
>How can I achieve that the contents are parsed without
>manually replacing
>the {#font#} tag with a regex function in the PHP script after
>pulling it from
>the database?
>
>I thought of adding a pre-filter function, but then I would
>also have to
>write a
>function to replace {#font#} with <FONT FACE....> and all the
>other tags,
>which would not make any sense, since smarty is supposed to do
>work like
>that. Any ideas?
>
>Martin.
>
>
>Martin Kloss
>
>Need music? http://www.selling-sound.com
>
>Like the author? Buy the book at:
>http://www.amazon.de/exec/obidos/ASIN/3898422194/lingmmugd
>
>Get your daily dose of Lingo at the LingoPark:
>http://www.lingopark.com
>
>
>
>
>--
>Smarty General Mailing List (http://smarty.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>
>