[PHPTAL] Missing semicolon and constants for variable keys
Bobby
bobby.phptal at oocr.org
Sat Apr 4 04:15:29 CEST 2009
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>
</div>
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
RepeatController
'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
${errorkey}"
tal:repeat="error errors">
<p tal:content="error">error.</p>
</div>
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
constant.
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>
</div>
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?)
Thanks!
Bobby
More information about the PHPTAL
mailing list