Hi Levi
I'm posting an extract from one of my previous posts, I think it might
give you an additional perspective to get out of the "tal:conditional"
grip in your template code..?
--- Begin Quote ---
There are two ways that you can achieve the desired result:
1) The TAL-complaint way is to flag the selected state in your category
list, thus in your source object:
$categoryList = array(
...
array(
id => 123,
name => 'My Category',
selected => false
),
array(
id => 456,
name => 'My Other Category',
selected => true
),
...
);
Then your PHPTAL code is as simple as:
2) The other option (I sometimes need to use this approach) is to write
your own custom modifier, that compares the object's value to another
value. Note: This, however, is NOT TAL compliant and will make your
template code specific to PHPTAL and thus your templates will not be
portable to other TAL implementations.
Here is an example modifier:
function phptal_tales_match($src, $nothrow) {
$srcArr = explode(',', trim($src));
if (count($srcArr) == 2) {
return '(' . PHPTAL_TalesInternal::path($srcArr[0], $nothrow) .'
== '. PHPTAL_TalesInternal::path($srcArr[1], $nothrow) . ')';
} else {
return PHPTAL_TalesInternal::path($src, $nothrow);
}
}
This modifier, when included before you initiate a PHPTAL object, can be
used as follows:
tal:attributes="selected match:category/id,article/category;
value category/id"
tal:content="category/name">
--- End Quote ---
Levi Stanley wrote:
Was wondering if there was a better way to deal with radio buttons &
selection box in phptal.
One way, is make an array, and pass it the choices to the template.
Or you can do it like the method below, however I was wondering if there
is a better way than doing it like this?
Choose Time
Morning
Morning
Evening
Evening
Morning
Evening
Best regards,
Levi
___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal
___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal