On 29-06-2010 at 16:41:15 Bas <kooy...@hotmail.com> wrote:

<html>
.....
<td tal:repeat="articles article" tal:content="article/getContent">
</td>
</html>

Now, how would I get the variable ${NAME} to be processed? What would be the right way to go about this?

The only way I can think of, is to insert the articles, execute the template and assign the output to PHPTAL again, parse again for the article variables and output to screen.

Anyone have a better idea?

First, keep in mind that TAL templates can execute arbitrary PHP code, so only allow templates to be edited by users you trust.


To execute additional TAL code, use should macros:

<div metal:use-macro="article_${id}/content" />

You can use ${} variables in macro name, and path to macro can be anything.

Now, if you want macro to load templates from database, rather from disk, write SourceResolver class that recognizes your macro paths and loads them:

class ArticleSource extends PHPTAL_SourceResolver
{
  function resolve($path)
  {
     if (looks_like_path_of_article($path)) {
        return new PHPTAL_StringSource(get_article_from_database($path));
     }
  }
}

$phptal->addSourceResolver(new ArticleSource());


This will create fake filesystem from which PHPTAL will be able to load templates.

--
regards, Kornel

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

Reply via email to