On Fri, 22 Apr 2011 22:26:03 +0100, <hosema...@poczta.onet.pl> wrote:

How to create new tag
I would like to create tag that automaticly includes js and css to document files from predefined directory like:

<tal:js src="jquery.js">
<tal:css src="style.css">

How to extend tal tags?

TAL doesn't use tags :) Elements in tal namespace are not output.

You could create your own attribute, e.g.

<script xmlns:yournamespace="…" yournamespace:src="jquery.js"/>

The easier option is to use prefilter to change this attribute into standard TAL attribute (e.g. a macro call or tal:content).

The hard way is to implement it the same way tal:content does it: by creating your own namespace (PHPTAL_Dom_Defs->registerNamespace()) and implementing your custom attribute by extending PHPTAL_Php_Attribute class, that writes code in before/after methods. I don't recommend that, because it's not documented and requires familiarity with PHPTAL's internals.

And the easiest solution is to create TALES prefix:

<script tal:content="include:jquery.js" />

function phptal_tales_include($expr, $nothrow)
return 'file_get_contents("your_directory/".'.phptal_tale($expr,$nothrow).')';

regards, Kornel Lesiński

PHPTAL mailing list

Reply via email to