Re: [SMARTY] parsing db content

From: Date: Wed, 05 Mar 2003 14:16:02 +0000
Subject: Re: [SMARTY] parsing db content
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8410@lists.php.net to get a copy of this message
Helo, On Wed, Mar 05, 2003 at 02:45:40PM +0100, Martin Kloss wrote: > 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. i can think of two possibilities: 1. use eval (see http://smarty.php.net/manual/en/language.function.eval.php ) but this is bad, since your content has to be compiled everytime it is pulled from the db. 2. (better) write a resource handler for your database (see http://smarty.php.net/manual/en/plugins.resources.php ) then you can access your content like a template and do things like $smarty->fetch('content:id123') or {include file="content:$id"} if you track timestamps of your changes inside the db, then smarty can cache the compiled "content"-templates like normal ones using these timestamps. have fun messju > Martin Kloss

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