Hello, I'm new to PHPTal and i've run into a few issues...

I want to eventually make an error list macro, my errors are sent to the
template under a constant key name,
for example:

interface AppConstants {
  const ERROR_KEY = 'error_key';

$template = new PHPTAL('example.html');
$template->set(AppConstants::ERROR_KEY, array('Yay, an error!', 'W00t'));

I want to be able to retrieve it using that same constant, this is where I start
to run into problems...

Here's my first try in example.html:

<div id="error" tal:repeat="error php:${AppConstants::ERROR_KEY}">
     <p tal:content="error">error.</p>

This generates:

$_tmp_1->error = new PHPTAL_RepeatController(${AppConstants::ERROR_KEY})$ctx =
$tpl->pushContext() ;
foreach ($_tmp_1->error as $ctx->error): ;

First, notice the missing semicolon ';' at the end of the first line
..._KEY})$ctx =...
If I add the semicolon it will then run, ${AppConstants::ERROR_KEY} will give
'error_key', but without minding the real value 'error_key' in the context,
which is understandable, the
result is no errors shown....

So I try this:

<div id="error" tal:define="errorkey php:AppConstants::ERROR_KEY; errors
                     tal:repeat="error errors">
<p tal:content="error">error.</p>

Which fails with the same semicolon problem as the first, but once manually
added in will get the desired results, BUT
as long as we don't define errorkey as error_key which will wipeout our context

Why go through all this trouble when I could have just done...

<div id="error" tal:repeat="error error_key">
<p tal:content="error">error.</p>

Dunno....Does anyone have suggestions to improve on this? Also, how can I fix
the missing semicolon problem?
(i've noticed in CodeWriter.php function flushCode that there are comments
"avoid adding ; after } and {" perhaps that may be preventing the semicolon?)



PHPTAL mailing list

Reply via email to