coding wizard please help me with displaying selected attributes
Permalink
Can someone please help me with displaying links related to selected attributes please?
I have a custom select attribute witk multiple values selected.
I need to display a different url based on the selected attribute.
This is what i have now in my code:
$materiaal = $c->getCollectionAttributeValue('project_materiaal'); //Custom Selection attribute
$selectedOptions = $c->getCollectionAttributeValue('project_materiaal');
if($selectedOptions == "leisteen"){
$materiaalUrl = "/leidekkers";
}
else {
$materiaalUrl = "/metalen";
}
But this is not working, all url's are getting displayed as '/metalen' now, so the first part of this code gets skipped.
I guess i need to do something with 'foreach', but i'm not a real coder so i don't know how i can fix this.
Some help from a real coder will be highly appreciated!
I have a custom select attribute witk multiple values selected.
I need to display a different url based on the selected attribute.
This is what i have now in my code:
$materiaal = $c->getCollectionAttributeValue('project_materiaal'); //Custom Selection attribute
$selectedOptions = $c->getCollectionAttributeValue('project_materiaal');
if($selectedOptions == "leisteen"){
$materiaalUrl = "/leidekkers";
}
else {
$materiaalUrl = "/metalen";
}
But this is not working, all url's are getting displayed as '/metalen' now, so the first part of this code gets skipped.
I guess i need to do something with 'foreach', but i'm not a real coder so i don't know how i can fix this.
Some help from a real coder will be highly appreciated!
You are not accessing the value of the select attribute properly. Because a select attribute could have more than one selection, you need to loop through the selections and check their "value" property. For example:
And for more details than you ever probably want to know about "related links" and select attributes, see the following threads:
http://www.concrete5.org/community/forums/block_requests/content-re...
http://www.concrete5.org/community/forums/customizing_c5/get-page-t...
http://www.concrete5.org/community/forums/customizing_c5/how-to-wan...
Also note that there's an addon in the marketplace that does "related links" -- I'm not sure if it is right for your situation, but if you're rather pay some money than spend the time coding it yourself, it might be worth looking into:
http://www.concrete5.org/marketplace/addons/related-pages/...
$materiaals = $c->getCollectionAttributeValue('project_materiaal'); $ist_leisteen = false; foreach ($materiaals as $materiaal) { if ($materiaal->value == 'leisteen') { $ist_leisteen = true; break; } } if ($ist_leisteen) { $materiaalUrl = '/leidekkers'; } else { $materiaalUrl = '/metalen'; }
And for more details than you ever probably want to know about "related links" and select attributes, see the following threads:
http://www.concrete5.org/community/forums/block_requests/content-re...
http://www.concrete5.org/community/forums/customizing_c5/get-page-t...
http://www.concrete5.org/community/forums/customizing_c5/how-to-wan...
Also note that there's an addon in the marketplace that does "related links" -- I'm not sure if it is right for your situation, but if you're rather pay some money than spend the time coding it yourself, it might be worth looking into:
http://www.concrete5.org/marketplace/addons/related-pages/...
Hi Guys,
Thanks for your responses and suggestions. I'm gonna take a look at all of them and try to make this work.
Thanks!
Thanks for your responses and suggestions. I'm gonna take a look at all of them and try to make this work.
Thanks!
http://www.concrete5.org/marketplace/addons/quick-attribute-view/...
You may also find this howto of use:
http://www.concrete5.org/documentation/how-tos/developers/concrete5...
If your select attribute is a multi-select, it will be returning an array, so you have to look for your comparison within the array using php in_array().
http://uk1.php.net/in_array
Or for a way to do stuff like this with no php coding - use my Magic Data addon.