What's wrong with my PHPTAL syntax?
.Quick question - I have the following, working syntax:
<td tal:define="owner record/owner_id; user user/id; mode php:(owner eq user)?'_edit':'_view'; linkname php:(owner eq user)?'Edit':'View';">
<a href="index.php?-table=${table}&-action=${mode}&id=${record/id}">${linkname}</a>
</td>
but I was expecting to be able to use the shorter:
<td tal:define="mode php:(record.owner_id eq user.id)?'_edit':'_view';linkname php:(record.owner_id eq user.id)?'Edit':'View';">
<a href="index.php?-table=${table}&-action=${mode}&id=${record/id}">${linkname}</a>
</td&g开发者_开发知识库t;
i.e. not having to define owner
and user
in order to get at them for the php:
test.
So my question is, how am I using the dot syntax wrong in the php:
context? (also, is there a simpler way to express this WITHIN THE TEMPLATE i.e. without changning the PHP external to the template?
This syntax is fine as long as record
and user
are objects (instances of classes). If they are arrays, then you need:
tal:define="mode php:(record['owner_id'] eq user['id'])
When you use TALES expressions, PHPTAL figures out object/array difference for you. If you use php:
, you have to watch out for differences between objects and arrays.
精彩评论