Kornel Lesiński <kor...@...> writes:

> 
> On 06-08-2010 at 13:03:20 Bas Kooij <kooy...@...> wrote:
> 
> > Sorry, I tried to simplify things by using a date tag, but this has just
> > caused confusion. I don't just need to replace a date tag, I need to  
> > replace a
> > tag named logos, which I'd like to replace with a macro containing TAL  
> > code to
> > insert a bunch of company logo's. I have now done it like this:
> >
> > In home.xhtml
> >
> > <tal:block metal:use-macro="main.xhtml/main">
> >     <tal:block metal:fill-slot="page">
> >
> >         <h1 tal:content="page/GetContent/GetTitel"></h1>
> >         [HOME]
> >
> >     </tal:block>
> > </tal:block>
> >
> > Then I use the following PreFilter:
> >
> > class HomePreFilter extends PHPTAL_PreFilter {
> >     function filter($src) {
> >         $content = [retrieve home page from db]
> >         $content = str_replace('[logos]', '<tal:block metal:use-
> > macro="logos.xhtml/logos" />', $content);
> >         return str_replace('[HOME]', $content, $src);
> >     }
> > }
> >
> > Which works fine. Is this the best way?
> 
> For changing [logos] to <tal:block metal:use-macro="logos.xhtml/logos" />  
> it's perfect.
> 
> I'm a bit concerned about retrieving pages from DB directly in the  
> prefilter. Keep in mind that prefilters are applied to all files, so it  
> would be run on logos.xhtml as well.
> 
> You could replace [HOME] with call to macro that is loads homepage via  
> resolver (prefilter will be applied to that resolved page too, so you can  
> have [HOME] that loads homepage with [logos] in it).
> 
> As you've noticed, either way can be made to work, but in PHPTAL the  
> concept is that:
> 
>   * Load, but don't replace in resolvers.
>   * Replace, but don't load in prefilters.
> 

Thank you,

Now I let my database repository classes implement PHPTAL_SourceResolver. I do 
have to let the SourceResolver ouput a macro, right? So if I want to resolve 
this (to load page with pageId 5):

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

I have to let the resolver output this:

    public function resolve($path) {
        if(path_starts_with("pageResolver_")) {
            $pagesId = trimleft($path, "pageResolver_");
            $pageContent = [get page from db with $pagesId]
            $content = '<tal:block metal:define-
macro="pageContent">'.$pageContent.'</tal:block>';
            return new PHPTAL_StringSource($content, $path);
        }
    }

It seems a little complicated to have to output another macro to get it to 
work. Anyway, thanks for all your help, I've got it all to work the way it 
should. Still think it's pretty complicated stuff for an essentially simple 
operation, ie. parse some TAL variable twice.

ps. Something very different: is there a reference available to the Translator 
inside the templates, or do I have to provide one myself? (I can start a new 
subject for the archives if you want)
 
Again, I appreciate your time, sorry for all the questions.

Regards,
Bas Kooij


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

Reply via email to