TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Libraries & Extensions (http://www.talkphp.com/libraries-extensions/)
-   -   What do you think about PHPTAL? (http://www.talkphp.com/libraries-extensions/3476-what-do-you-think-about-phptal.html)

awuehr 10-14-2008 07:10 AM

What do you think about PHPTAL?
 
Hi folks,

I'm curios if you know PHPTAL and what you think about it. IMHO it's the best templating system available for PHP. No PHP code or proprietary tags in the template files, just valid XML/XHTML.

But what's your opinion?


Best regards,

Alex

xenon 10-14-2008 08:54 AM

It kicks ass. Also has integrated internationalization, besides forcing you to write valid XHTML and it's way faster than Smarty.

sketchMedia 10-14-2008 07:05 PM

Looks interesting, thanks

codefreek 10-24-2008 01:09 AM

Quote:

Originally Posted by sketchMedia (Post 18818)
Looks interesting, thanks

what he said ;)

awuehr 10-24-2008 08:34 AM

I think a poll about what template engines people use could be interesting. But which PHP template engines except from Smarty and PHPTAL are worth to be mentioned?

Runar 11-06-2008 12:29 PM

I am considering implanting this on my site, but I do have one issue: In my opinion, a template system does not only separate backend from frontend, but it also makes sure I do not have to repeat i.e. my HTML header on every file. How may I do this in PHPTAL?

I used to include a header file on top of every page, but this does not work with PHPTAL.

awuehr 11-06-2008 01:51 PM

Hi Runar,

this is done via Macros.

Lets say you have one file (macros.html) containing your header, footer, etc. containing this code:

HTML Code:

<div metal:define-macro="header">
    Your header here
</div>

<div metal:define-macro="footer">
    Your footer here
</div>

In your HTML page you just write
HTML Code:

<div metal:use-macro="macros.html/header" />
and
HTML Code:

<div metal:use-macro="macros.html/footer" />
where you want them to be.

Way better is to use slots:
Lets say you have one template for all your pages (template.html):

HTML Code:

<html metal:define-macro="page_template">
  <head></head>
  <body>
        <tal:block metal:define-slot="content" />
  </body>
</html>

Create another file (page.html):
HTML Code:

<tal:block metal:use-macro="template.html/page_template">
    <tal:block metal:fill-slot="content">
        Your static Content here
        ${dynamic_content}
        or
        <span tal:content="another_dynamic_content" />
    </tal:block>
</tal:block>

To render this just call

PHP Code:

$phptal = new PHPTAL();
$phptal->setSource('page.html');
$phptal->dynamic_content 'something';
$phptal->another_dynamic_content 'something else';

echo 
$phptal->execute(); 

That's all. Btw. you can define and fill more than one slot...

You should also read the manual for PHPTAL on PHPTAL :: Template Attribute Language for PHP

Greetings,

Alex

Runar 11-06-2008 02:40 PM

Ah, great! I was looking for something like that in the manual, but tried to understand the basics first. Now it works perfectly!

I will try to solve my last issue myself, but in case you already know the solution: I want to display an extra </tr><tr> if the number of people repeated (with tal:repeat) is 4. Any suggestions?

Edit: I followed your example, but had to replace metal:fill-slot="content" with metal:define-slot="content" in template.html.

Tanax 11-06-2008 03:46 PM

Does anyone have a tutorial how to integrate this into zend framework??

awuehr 11-06-2008 03:54 PM

You should consider to use an 3d array like
PHP Code:

$phptal->persons = array(
    array(
'person1''person2''person3''person4'),
    array(
'person5''person6''person7''person8'),
    array(
'person9''person10''person11''person12')
); 

HTML would be
HTML Code:

<table>
    <tr tal:repeat="person_line persons">
        <td tal:repeat="person person_line" tal:content="person">...</td>
    </tr>
</table>

Greetings,

Alex

awuehr 11-06-2008 03:57 PM

Eat this: Zend_View_PhpTal - Matthew Ratzloff - Zend Framework Wiki :-D
I don't know if it works with current releases of ZF, but i've used that successfully with ZF 1.5

Greetings


Alex

awuehr 11-06-2008 04:56 PM

Btw you can use PHPTAL for templating any XML-Output like RSS/Atom feeds or XSL-FO where XSLT transformation is oversized.


Greetings

Alex

Tanax 11-07-2008 08:38 AM

awuehr, you seem quite knowledged with PHPTAL. You're not considering to make a tutorial? :-)

awuehr 11-07-2008 09:11 AM

Good idea. I really should do this, but I am not very good explaining technical things in english.

Is there a possibility to preview an article?

Tanax 11-07-2008 09:50 AM

I'm sure you'll do absolutely great :-)

No it doesn't look like you can =/

Runar 11-07-2008 10:30 AM

PHPTAL was surprisingly easy to understand. The manual explains everything quite well, but I would not say no to a tutorial. It is always better to understand when and how to use the different functions, not only how they work and what they do.

awuehr 11-10-2008 09:30 AM

First part (basics) of a short tutorial is waiting to be approved... :)


Greetings,

Alex

Tanax 11-10-2008 09:52 AM

Awesome :-D I'll check it as soon as it goes public :-)

awuehr 11-10-2008 10:04 AM

But the first one is VERY basic...

Tanax 11-10-2008 10:07 AM

Yea well, I haven't really done anything in PHPTAL, so that's just good that it's basic :-)


All times are GMT. The time now is 11:56 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0