Adding SELECT attribute options for a page

Permalink
I have created the SELECT attribute as follows
CollectionAttributeKey::add('tab_attr', t('Tab Attribute'), false, null, 'SELECT');


Now I want to add the values (options) per page level
$ak=CollectionAttributeKey::getByHandle('tab_attr');
SelectAttributeTypeOption::add( $ak, 'Tab1', 0, 0);


The above code will add the options globally, but I want it in page level.
I'm trying the following code, but it is not working
$curPage = Page::getCurrentPage();
$curPage->setAttribute($ak, 'Tab1');


How to add the SELECT attribute for a page, so that I can get the following values
$options = $curPage->getCollectionAttributeValue('tab_attr');


Thanks in advance for your help,
Bala

 
jordanlev replied on at Permalink Reply
jordanlev
You can't have different options for different pages. The options of the select attribute (or any attribute for that matter) will be the same across the whole site. If you want different options for different pages you would need to create different attributes.
kumarbalap replied on at Permalink Reply
Hi Jordan

If I follow the steps manually, as mentioned in the below page, I'm able to get different options for the same attribute

http://www.concrete5.org/documentation/how-tos/developers/creating-...

I'm just wondering, how to do this through scripting

Thanks,
Bala
JohntheFish replied on at Permalink Reply
JohntheFish
While the attribute has a single set of options, you could subset those options shown for a particular page with some jQuery.
// This is jquery-ish pseudo-code to outline the solution
switch (page_path)
  case 'a/page/path'
    $(the_attribute_select options).each(function(){
      if (this_option_value is_not_wanted){
        $(this_option).remove()
      }
    });
// etc....

This would obviously require some development work and would need to be loaded and execute when the attribute value was edited.
kumarbalap replied on at Permalink Reply
Able to save the options

$opt = SelectAttributeTypeOption::add($ak, 'Tab1', 0, 0);
$curPage->setAttribute($ak, $opt);


and getting the values properly by using $curPage->getCollectionAttributeValue('tab_attr');

Thanks,
Bala
kumarbalap replied on at Permalink Reply
getting some problem with saving multiple options :(

As Jordan said, I think its better to have separate attributes per page.

Can anybody please tell me how multiselect works for a page

Thanks,
Bala
JohntheFish replied on at Permalink Reply
JohntheFish
Multiselect shows on the page properties as a list of checkboxes that you tick.
kumarbalap replied on at Permalink Reply
ya, actually I'm hiding it for the enduser, and managing it on my own, there I'm facing the pbm.

Basically I'm creating a TAB component based on this SELECT attr.

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.