> 
> > Slightly off topic... 
> > 
> > I really love PHPTal, it has cut development time for implementing 
templates 
> > in half. 
> > The only time I get stuck is when I have to insert dynamic templates into 
my 
> > PHPTal template files. This is quite a common occurrence when clients use 
a content 
> > management system to edit pages. I want them to be able to insert some 
sort of 
> > tags in the CMS, ie. [DATE], which I can then replace with PHPTal code, 
for instance 
> > <span tal:content="date | nothing" />. 
> 
> This is what prefilters are for:
> 
> class DateMagic extends PHPTAL_PreFilter 
> {
>   function filter($src) {return str_replace('[DATE]', '<span 
tal:content="date | nothing" />', $src);}
> }
> 
> $phptal->addPreFilter(new DateMagic());
> 

I tried usign PreFilters, but that doesn't seem work for inserted content, 
only for code which is hard coded in the template. So if I retrieve the html 
with the [DATE] tag from a database, insert it into a variable in my TAL 
template, the PreFilter never fires for the [DATE] tag. If I put the [DATE] 
tag in the template file itself it does work.

I have a working solution now. I have this in the home.xhtml template:

<tal:block metal:use-macro="main.xhtml/main">
     <tal:block metal:fill-slot="page">

         <tal:block metal:use-macro="customMacro/customMacro" />

     </tal:block>
</tal:block>

And I use the following SourceResolver:

class MySourceResolver implements PHPTAL_SourceResolver {
    public function resolve($path) {
        if($path == 'homeMacro') {
            $pageContent = [retrieve html with DATE tag from DB]
            $content = '<tal:block metal:define-
macro="customMacro">'.$pageContent.'</tal:block>';
            $content = str_replace('[DATE]', '19-02-1981', $content);
            return new PHPTAL_StringSource($content, 
PHPTAL_StringSource::NO_PATH_PREFIX.md5($pageContent));
        }
    }
}

Is this the easiest/only way to achieve what I want?

Thanks for your time,
Bas Kooij


_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to