Working with a Custom Select Attribute
Permalink
Hi all,
I'm working with a custom select attribute and unfortunately am too much of a PHP novice to get it to work properly. If someone wants to give me a few pointers, it would be greatly appreciated.
Here is the current code:
I get a fatal error at the first line: call to a member function getCollectionAttributeValue() on a non-object. What I want to do is create some code that can sense if something is selected within the custom attributes ('compatible_browsers' and 'incompatible_browsers') and, if so, print out some HTML. Something like this:
I think there may be a better way to do this than an if-statement (again, PHP novice), but that seems to be the least of my worries.
Is there something I'm missing with trying to access my custom attribute? Modifying the Thumbview template for the Page List block is about all the experience I have, which is where I got the $cobj->getCollectionAttributeValue('attribute_handle'); line.
I'm working with a custom select attribute and unfortunately am too much of a PHP novice to get it to work properly. If someone wants to give me a few pointers, it would be greatly appreciated.
Here is the current code:
<?php // name objects for the custom attributes $compatible = $cobj->getCollectionAttributeValue('compatible_browsers'); $incompatible = $cobj->getCollectionAttributeValue('incompatible_browsers'); ?>
I get a fatal error at the first line: call to a member function getCollectionAttributeValue() on a non-object. What I want to do is create some code that can sense if something is selected within the custom attributes ('compatible_browsers' and 'incompatible_browsers') and, if so, print out some HTML. Something like this:
<?php $browserCompatible = '<img class="compatibility-icon" src="<?=$this->getThemePath();?>/css/images/browser-compatible.png" alt="Compatible" />'; $browserIncompatible = '<img class="compatibility-icon" src="<?=$this->getThemePath();?>/css/images/browser-incompatible.png" alt="Compatible" />'; $browserUntested = '<img class="compatibility-icon" src="<?=$this->getThemePath();?>/css/images/browser-unknown.png" alt="Compatible" />'; // cycle through whether the browser is compatible or incompatible. If neither, it must be untested. if($compatible && $compatible == "Firefox") { print $browserCompatible; } elseif($incompatible == "Firefox") { print $browserIncompatible; } else { print $browserUntested; }; ?>
I think there may be a better way to do this than an if-statement (again, PHP novice), but that seems to be the least of my worries.
Is there something I'm missing with trying to access my custom attribute? Modifying the Thumbview template for the Page List block is about all the experience I have, which is where I got the $cobj->getCollectionAttributeValue('attribute_handle'); line.
Indeed, that turned out to be it. I used $c instead of $cobj. Begins working again.
Unfortunately I still haven't figured out how to use the Select attribute to my advantage. I've since replaced it with Checkbox attributes instead.
It works, but it's not pretty.
Is there a way of using the Select attribute to return a boolean value that I could use in a script like this?
Unfortunately I still haven't figured out how to use the Select attribute to my advantage. I've since replaced it with Checkbox attributes instead.
It works, but it's not pretty.
$safari = $c->getCollectionAttributeValue('safari_c'); $safariNot = $c->getCollectionAttributeValue('safari_inc'); $firefox = $c->getCollectionAttributeValue('firefox_c'); $firefoxNot = $c->getCollectionAttributeValue('firefox_inc'); $chrome = $c->getCollectionAttributeValue('chrome_c'); $chromeNot = $c->getCollectionAttributeValue('chrome_inc'); $opera = $c->getCollectionAttributeValue('opera_c'); $operaNot = $c->getCollectionAttributeValue('opera_inc'); $mobile = $c->getCollectionAttributeValue('mobile_c'); $mobileNot = $c->getCollectionAttributeValue('mobile_inc'); $ie6 = $c->getCollectionAttributeValue('ie6_c'); $ie6Not = $c->getCollectionAttributeValue('ie6_inc'); $ie7 = $c->getCollectionAttributeValue('ie7_c'); $ie7Not = $c->getCollectionAttributeValue('ie7_inc'); $ie8 = $c->getCollectionAttributeValue('ie8_c');
Viewing 15 lines of 18 lines. View entire code block.
Is there a way of using the Select attribute to return a boolean value that I could use in a script like this?
Try this quick code before the line above to debug:
I suspect the $cobj to be null (empty).