On 06-08-2010 at 13:03:20 Bas Kooij <kooy...@hotmail.com> 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>


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.

regards, Kornel

PHPTAL mailing list

Reply via email to