[PHPTAL] Re: SourceResolver path in nested macro

2010-08-06 Thread Bas Kooij
Thanks for the reply,

So if I name the macro customMacro/customMacro the resolver would recognize 
it? But 
that makes the second part irrelevant for CustomResolvers right?

Slightly off topic... 

I really love PHPTal, it has cut development time for implementing templates 
in half. 
The only time I get stuck is when I have to insert dynamic templates into my 
PHPTal 
template files. This is quite a common occurrence when clients use a content 
management system to edit pages. I want them to be able to insert some sort of 
tags in 
the CMS, ie. [DATE], which I can then replace with PHPTal code, for instance 
span 
tal:content=date | nothing /. 

The way to go for this at the moment is using CustomSourceResolvers, which are 
not 
entirely trivial to implement. Would it be a bad idea to implement some sort 
of custom 
keyword which would allow inserting code into the template? What if you could 
write 
the following in your PHPTal template:

div tal:content=reparse cmsHtml /

Where the cmsContent would be a TAL variable containing more TAL containing 
more TAL 
code. This way I could retrieve the HTML with tags from the database, replace 
tags 
with TAL code and insert it into my templates very easily.

Sorry for the rant, I know all this can be achieved at the moment. I'm just 
throwing 
an idea out there.

Regards,

Bas Kooij


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


[PHPTAL] Re: SourceResolver path in nested macro

2010-08-06 Thread Bas Kooij
 
  Slightly off topic... 
  
  I really love PHPTal, it has cut development time for implementing 
templates 
  in half. 
  The only time I get stuck is when I have to insert dynamic templates into 
my 
  PHPTal template files. This is quite a common occurrence when clients use 
a content 
  management system to edit pages. I want them to be able to insert some 
sort of 
  tags in the CMS, ie. [DATE], which I can then replace with PHPTal code, 
for instance 
  span tal:content=date | nothing /. 
 
 This is what prefilters are for:
 
 class DateMagic extends PHPTAL_PreFilter 
 {
   function filter($src) {return str_replace('[DATE]', 'span 
tal:content=date | nothing /', $src);}
 }
 
 $phptal-addPreFilter(new DateMagic());
 

I tried usign PreFilters, but that doesn't seem work for inserted content, 
only for code which is hard coded in the template. So if I retrieve the html 
with the [DATE] tag from a database, insert it into a variable in my TAL 
template, the PreFilter never fires for the [DATE] tag. If I put the [DATE] 
tag in the template file itself it does work.

I have a working solution now. I have this in the home.xhtml template:

tal:block metal:use-macro=main.xhtml/main
 tal:block metal:fill-slot=page

 tal:block metal:use-macro=customMacro/customMacro /

 /tal:block
/tal:block

And I use the following SourceResolver:

class MySourceResolver implements PHPTAL_SourceResolver {
public function resolve($path) {
if($path == 'homeMacro') {
$pageContent = [retrieve html with DATE tag from DB]
$content = 'tal:block metal:define-
macro=customMacro'.$pageContent.'/tal:block';
$content = str_replace('[DATE]', '19-02-1981', $content);
return new PHPTAL_StringSource($content, 
PHPTAL_StringSource::NO_PATH_PREFIX.md5($pageContent));
}
}
}

Is this the easiest/only way to achieve what I want?

Thanks for your time,
Bas Kooij


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


[PHPTAL] Re: SourceResolver path in nested macro

2010-08-06 Thread Bas Kooij
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?

Regards,
Bas Kooij


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