[PHPTAL] Simple question from a TAL newbie.
Brian Peiris
brianpeiris at gmail.com
Wed Jan 24 01:54:37 CET 2007
The code below shows my very first attempt at using TAL. It took me
quite a while to get to this point, and it still seems wrong.
Basically if the "titleSuffix" variable is set in the php code, the
page title should display:
"My Website - Test Page"
and if "titleSuffix" is not set (i.e. that line is commented out), the
title should display:
"My Website"
However it seems redundant and messy to have two <title> tags in the
template, is there a better (cleaner) way of achieving the same
result?
Thanks,
Brian.
[php]
<?php
require_once 'PHPTAL.php';
// create a new template object
$tpl = new PHPTAL('template.html');
$tpl->titleSuffix = "Test Page";
// execute the template
try{echo $tpl->execute();}
catch (Exception $e){echo "<pre>{$e->getMessage()}</pre>";}
?>
[template]
<tal:block define="global titlePrefix string:My Website"/>
<title
tal:condition="exists: titleSuffix"
tal:content="string:$titlePrefix - $titleSuffix"
>
</title>
<title tal:condition="not:exists: titleSuffix"
tal:content="titlePrefix" ></title>
More information about the PHPTAL
mailing list