PageList and "select Attribute" - how to get selected value?

Permalink
I added "select" attribute to group of pages and create pagelist custom template.

Now I want to print inside the view.php of [page list] block - the name of the "selected" option (one or more)

Example: Page list like this (each page list item - echo the subject)
http://noeeko.com/category/projects/illustration/...

*** I remember i saw in the past Tut about this in C5 docs. If someone know this please add link

siton
 
hutman replied on at Permalink Best Answer Reply
hutman
You will need to create a custom template for the PageList block. You do this by creating a directory in /application/blocks which would be called page_list then create a templates directory inside of that. Now go to the /concrete/blocks/page_list and copy the view.php into your /application/blocks/page_list/templates directory and rename it, the name will determine what the custom template will be called (i.e. test_template = Test Template). Then make your changes to that file and apply the custom template to the block you are using.

To get the value of a select attribute within the PageList Custom Template you would do something like this

echo $page->getAttribute('select_attribute_handle');
siton replied on at Permalink Reply
siton
Thanks. Weird i first do this and get empty vars. I think it was cache problem

I saw her for example more complicated code. And dont understand the problem
https://gist.github.com/hissy/6255509...
siton replied on at Permalink Reply
siton
i create isotope galley - so i need for "1.seo" - "2.mobile" (page with two values - " select multiple") - how to create two buttons?

(the echo - give me "1. seo mobile")
hutman replied on at Permalink Reply
hutman
Sorry, you didn't say it was a multi select attribute, you'll need to do this instead

$attributeOptions = $page->getCollectionAttributeValue('attribute_handle');
foreach($attributeOptions as $option){
    echo $option->value;
}
siton replied on at Permalink Reply
siton
Thanks :) Works perfect
tobyme replied on at Permalink Reply
Hi Siton - dropped you a PM.

Just wondering if you would be willing to share how you managed this. I would love to be able to create a filterable page list but I have had a look and simply dont have the skills to do it?

I have one on 5.6 and am upgrading a site and am stuck as how to get that functionality

Thanks
siton replied on at Permalink Reply
siton
You need to create custom template + page attributes to "filter by". Than adapt the right syntax of the specific JS library you choose and added to you project - some filter js:
http://isotope.metafizzy.co/
http://mixitup.kunkalabs.com/
http://getuikit.com/docs/grid-js.html...

Sorry, Its impossible to explain how to do this in forum post (long topic). Try use google/youtube to find "how to" or tut about "custom template" & js + download some addons that use js (galleries, dropdowns navs ect.) and try to learn this issue.

I send you by email Example.
aenowwebsite replied on at Permalink Reply
This didn't work for me in version 8.1.0. Here is what I came up with that will get the selected values as an array in case it can be of any use to anyone else.

if (
            !is_null($page->getCollectionAttributeValue('attr_nm')) &&
            !is_null($page->getCollectionAttributeValue('attr_nm')->getSelectedOptions()) &&
            !is_null($page->getCollectionAttributeValue('attr_nm')->getSelectedOptions()->getValues())
        ) {
            $values = (
                array_map(
                    function ($row) {
                        return $row->getSelectAttributeOptionValue();
                    },
                    $page->getCollectionAttributeValue('attr_nm')->getSelectedOptions()->getValues()
                )
            );
        }
ghostjohn replied on at Permalink Reply
Thanks so much for posting this - I couldn't find it documented anywhere (like much of C5) how to do this!