TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-18-2008, 09:11 AM   #21 (permalink)
The Addict
 
zxt3st's Avatar
 
Join Date: Apr 2008
Posts: 200
Thanks: 18
zxt3st is on a distinguished road
Default

hmm, i havn't tried using such PHPTal and any other templating system for php projects. But it really sounds interesting :)
zxt3st is offline  
Reply With Quote
Old 01-07-2009, 01:09 PM   #22 (permalink)
The Wanderer
 
Join Date: Jan 2009
Posts: 8
Thanks: 1
nightowl is on a distinguished road
Default

2 questions about PHPTal:

- first of all, I'm used to putting all logic concerning a certain part of the app in 1 PHP page. eg. a form to search and show results, would be in 1 PHP page with a show_form() and a search() functions, and a "if (!isset($_REQUEST['submit'])) show_form() else search()" statement. You get the point. What is the best way to do this, using PHPTal? AFAIK, you can only define 1 template in a file (contrary to e.g. patTemplate, which I used before).

Is the best way just using <tal:block condition="sumitted">...show results...</tal:block><tal:block condition="not:sumbitted">...show form...</tal:block> ?


- about the 3-dimensional array solution in this topic: isn't the goal of a templatingsystem that it should make the viewing of data unrelated to the php code ? If you first need to define the number of cols in your php code (by defining the array in such a way), then what is the goal of the templating? I'd like my template to make the decision about the number of cols ...
Is that possible?
nightowl is offline  
Reply With Quote
Old 01-08-2009, 05:50 AM   #23 (permalink)
The Contributor
 
awuehr's Avatar
 
Join Date: Oct 2008
Location: Nuremberg, Germany
Posts: 26
Thanks: 3
awuehr is on a distinguished road
Default

First of all you can define as much templates in one file, as you want. This file only has to be valid XML.

HTML Code:
<html>
    <head>...</head>
    <body>
        <tal:block condition="submitted">...show results...</tal:block>
        <tal:block condition="not:submitted">...show form</tal:block>
    </body>
</html>
is ok, but you even could write
HTML Code:
<tal:block>
    <html tal:condition="submitted">
        <head>...</head>
        <body>
            ...show results...
        </body>
    </html>
    <html tal:condition="not:submitted">
        <head>...</head>
        <body>
            ...show form...
        </body>
    </html>
</tal:block>
I'd prefer to define macros and use them, when they are required:

HTML Code:
<html>
    <head>...</head>
    <body>
        <tal:block metal:define-macro="submit">...show results...</tal:block>
        <tal:block metal:define-macro="form">...show form...</tal:block>
        <tal:block metal:use-macro="${action}" />
    </body>
</html>
In PHP you would write:
PHP Code:
$tal = new PHPTAL(<template.file>);
$tal->action = (isset($_REQUEST['submit']))?'submit':'form';
// define some other TAL variables to display...
echo $tal->execute(); 
If you use macros, you can put them to an external file and reuse them in other templates.

Another way would be to use slots.

About the 3d-array-problem:
Until now I did not find a way to do this in PHPTAL, there is no way to exit a loop when a condition (cols == x) becomes true or whatever.

How would you do this in patTemplate (which I don't know until now)?
__________________
Send a message via ICQ to awuehr Send a message via Skype™ to awuehr
awuehr is offline  
Reply With Quote
Old 01-08-2009, 12:23 PM   #24 (permalink)
The Wanderer
 
Join Date: Jan 2009
Posts: 8
Thanks: 1
nightowl is on a distinguished road
Default

The idea to use macro's for the form / show results question is great. It seems like a valid alternative to adding the conditon statements.


I had gotten to this point.


search.php:

Code:
<?php
include_once( 'PHPTAL.php');
$tpl = new PHPTAL();
$tpl->setTemplateRepository('templates');
$tpl->setTemplate('search.tpl');
$tpl->title = "Test van PHPTal";
$tpl->globalpage = "global.tpl/globalpage";

function show_form() {
    global $tpl;
	$tpl->mode = 'showform';
}

function search() {
	global $tpl;	
	$tpl->mode = 'showresult';
}

if (!isset($_REQUEST['submit'])) {
	show_form();
}
else {
	search();
}

echo $tpl->execute();
?>
Using 2 templates: a "general" one, that will be used by every PHP page and that sets the general layout of the site:

global.tpl
Code:
<html metal:define-macro="globalpage">

<head>
<title tal:content="title">Title here</title>
</head>

<body>
<table>

<tr>
	<td valign="top">
	
		<span metal:define-slot="pagemenu">
		[ <a href="/">Home</a> ]
		</span>
	
	</td>
	<td>
	
		<span metal:define-slot="pagecontent"></span>
		
	</td>
</tr>
</table>


</body>
</html>
and a specific one, that defines the screens for this PHP page

search.tpl
Code:
<tal:block metal:use-macro="${globalpage}">
<tal:block metal:fill-slot="pagecontent">

<tal:block tal:condition="php: mode=='showform'">
	...show the form...
</tal:block>

<tal:block tal:condition="php: mode=='showresult'">
    ...show the results...
</tal:block>
	
</tal:block>
</tal:block>
Given your excellent view on the best way to implement PHPTal: what do you think? How could I improve this?


About the 3-D-array and patTemplate: it also depends on your PHP code. Although you don't need run through your array of results, store them in a second array and add that to the page afterwards. It seems a bit overhead, the way PHPTal forces you to do it. But I'm not claiming it's that much better in patTemplate. I just hoped there was a better way in PHPTal :)

FYI, the patTemplate way: let's say we have something

Code:
$persons_res = pg_query("select firstname, lastname from persons");
while ($person = pg_fetch_object($persons_res)) {
  $tmpl->addObject('person', $person);
  $tmpl->parseTemplate('person', 'a');
  if ($i % $num_records_per_row == 0) {
    $tmpl->parseTemplate('row', 'a');
    $tmpl->clearTemplate('person');
  }
}
Where the template looks like this:

Code:
<h1>All persons</h1>
<table>
<patTemplate:tmpl name="row">
<tr>
<patTemplate:tmpl name="person">
<td>{FIRSTNAME} {LASTNAME}</Td>
</patTemplate:tmpl>
</tr>
</patTemplate:tmpl>
My experience with patTemplate: it served me very well for different big projects, but it's a bit cumbersome (too much text) to add conditional viewing of certain buttons etc.
nightowl is offline  
Reply With Quote
Old 01-08-2009, 12:54 PM   #25 (permalink)
The Contributor
 
awuehr's Avatar
 
Join Date: Oct 2008
Location: Nuremberg, Germany
Posts: 26
Thanks: 3
awuehr is on a distinguished road
Default

Your solution looks quite good. :)

About the 3d-array-problem: Even in your code the template itself does not decide how many cols to display. You're doing this in your PHP script. So IMO there is no difference between telling patTemplate to start a new row or building an array with the right number of cols. In both cases there is no logic neither in patTemplate Templates nor in PHPTAL Templates. They just display, what you tell them via PHP.
__________________
Send a message via ICQ to awuehr Send a message via Skype™ to awuehr
awuehr is offline  
Reply With Quote
Old 01-08-2009, 03:12 PM   #26 (permalink)
The Wanderer
 
Join Date: Jan 2009
Posts: 8
Thanks: 1
nightowl is on a distinguished road
Default

as I said ... "About the 3-D-array and patTemplate: it also depends on your PHP code.".So yes, you are right. I thought that Smarty maybe has something to tackle it, dunno. I don't know Smarty besides some examples. I haven't seen a templating engine at work that does the formatting in cols in a convenient way.

Only diff between patTemplate and PHPTal is that PHPTal requires to create another array apparently, so there is a bit of overhead. But there are worse things than that :)
nightowl is offline  
Reply With Quote
Old 01-08-2009, 03:18 PM   #27 (permalink)
The Wanderer
 
Join Date: Jan 2009
Posts: 8
Thanks: 1
nightowl is on a distinguished road
Default

as I said ... "About the 3-D-array and patTemplate: it also depends on your PHP code.".So yes, you are right. I thought that Smarty maybe has something to tackle it, dunno. I don't know Smarty besides some examples. I haven't seen a templating engine at work that does the formatting in cols in a convenient way.

Only diff between patTemplate and PHPTal is that PHPTal requires to create another array apparently, so there is a bit of overhead. But there are worse things than that :)


About my PHPTal solution: I'm not that pleased with the tal:blocks and conditions. It looks a bit awkard. but it's probably a matter of getting used to it;
nightowl is offline  
Reply With Quote
Old 01-23-2009, 12:43 PM   #28 (permalink)
The Contributor
 
awuehr's Avatar
 
Join Date: Oct 2008
Location: Nuremberg, Germany
Posts: 26
Thanks: 3
awuehr is on a distinguished road
Default

There's a brandnew tutorial how to integrate PHPTAL with ZF:
http://taat.pl/article/zend_framework_tutorial/
__________________
Send a message via ICQ to awuehr Send a message via Skype™ to awuehr
awuehr is offline  
Reply With Quote
The Following User Says Thank You to awuehr For This Useful Post:
nightowl (02-06-2009)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:10 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design