Retuning page attributes as an array
Permalink
To output page attributes I'm using:
$page = Page::getCurrentPage();
echo $page->getAttribute('handle');
If the attribute type is 'Select' then multiple selections are all output separated by spaces. Is it possible to get all selected values as an array so that I can format the output?
$page = Page::getCurrentPage();
echo $page->getAttribute('handle');
If the attribute type is 'Select' then multiple selections are all output separated by spaces. Is it possible to get all selected values as an array so that I can format the output?
That works, until the values have spaces in them :)
I'm sure there must be functions to access this but I don't know where to start looking.
Joe
I'm sure there must be functions to access this but I don't know where to start looking.
Joe
$selectedOptions = $c->getAttribute('handle'); if($selectedOptions instanceof SelectAttributeTypeOptionList && $selectedOptions->count() > 0) { foreach($selectedOptions as $opt) { echo $opt } }
simple as that
Muchas gracias. How simple was that!
I don't understand how echo $c->getAttribute('handle') works if it's an array though, normally the output would be 'Array'?
I don't understand how echo $c->getAttribute('handle') works if it's an array though, normally the output would be 'Array'?
do a var_dump() on it, its an object that has an array
Ouch, sorry :(
Have you tried browsing throughhttp://www.concrete5.org/api/ ?
(If you do find something, please post it!)
Thanks + good luck!
Have you tried browsing throughhttp://www.concrete5.org/api/ ?
(If you do find something, please post it!)
Thanks + good luck!
I guess there's a more elegant way - maybe one of the experts knows more :)
HTH!