On 03-12-2009 at 15:42:41 Michał <hosema...@poczta.onet.pl> wrote:

What do you need this for? Why not simply execute the template?

Let me explain.
I am gonna use phptal template bot for generating content at server side and
client side. I found interesting project (Javascript template engine)

http://javascriptly.com/2008/08/a-better-javascript-template-engine/

So to make one template for Javascript and PHP I need this method.

Well, I wouldn't use scripts from anybody who wrote href="javascript:void(0)" ;)


If you're reading data via AJAX, then you can still use PHPTAL to generate those fragments (wrap them in a macro and execute it from simple template that just calls the macro).


If you want to use that JS engine anyway...

It'll be easier to remove TAL if you only use attributes, i.e. <x tal:content="foo"> instead of <x>${foo}</x>.


Then try using XPath or XSLT to remove TAL attributes. You'll need to add appropriate namespace declarations to XML (mentioned in manual for every namespace) and declare them in XPath:


$xml = DOMDocument::loadXML('<html xmlns="http://www.w3.org/1999/xhtml"; xmlns:tal="http://xml.zope.org/namespaces/tal";>...');
$xp = new DOMXPath($xml);
$xp->registerNamespace('tal',"http://xml.zope.org/namespaces/tal";);
foreach($xp->query('//@*[namespace-uri(.) = "http://xml.zope.org/namespaces/tal";]') as $attr)
{
$attr->ownerElement->removeAttributeNS($attr->namespaceURI, $attr->localName);
}
$noattr = $xml->saveXML();


--
regards, Kornel

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

Reply via email to