Get Child Page Attribute and write out div

Permalink
Hi,
I have an Pages Attribute I created called price_reduced.
I've added this to a page and use the following code to write a div in my page:
<?php 
                    global $c;  // may not be needed - should be the current page object
                    $price_red=$c->getCollectionAttributeValue('price_reduced');
                    switch ($price_red){
                        case true:
                            echo "<div class='price-reduced'></div>";
                            break;
                        case false:
                            break;
                        default :
                            break;
                    } 
                ?>


This works great, but I also have a page list and I want to get the attribute of the child pages in that list and write out a div in my list.
Im using page list teasers add-on and my code for my list looks like this so far:

<div class="ccm-page-list-description">
        <div class="veh-titles">
        <h3 class="ccm-page-list-title"><a <?php   echo $target?>href="<?php   echo $nh->getLinkToCollection($cobj)?>"><?php   echo $title?></a></h3></div>
        <?php   $plth->output_page_blocks($cobj, $excerptBlocks, $truncateChars); ?>
        <a class="btn-details" href="<?php   echo $nh->getLinkToCollection($cobj)?>">">View Full Details</a>
                </div>



What do I need to add, I haven't a clue how to do this??

Thanks in advance

Dave

madesimplemedia
 
JohntheFish replied on at Permalink Reply
JohntheFish
If you want to do it all in php, you need to create a custom template for page list teasers and within the loop that fetches each teaser, get the target page and then get the attribute value for it as you are already doing for the individual pages.

To avoid php, this is a typical application for Magic Data. (Magic Data has a Page List teasers template.) You can embed a suitable magic data token in the text of the page that gets pulled into the teaser. Something like:
[% ORIGINAL_PAGE ​ATTRIBUTE "price_reduced" END_ON_NULL '<div class="price_reduced"></div>' %]
Then assign the original content block and teaser block magic data templates.

What this does:
ORIGINAL_PAGE - in a list, gets the listed page ID, else gets the current page ID.
​ATTRIBUTE "price_reduced" - gets the value of the attribute for the page.
END_ON_NULL - skips if the attribute is false
'<div .... etc' - returned if the attribute is true
madesimplemedia replied on at Permalink Reply
madesimplemedia
Thanks for the reply John.

Can you give me a bit of syntax re the PHP solution, I'm a complete php n00b really.

I think I will try out Magic Data as well to see how that works :)
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
You need to create a new custom_teasers template copied from the existing page list teasers template.

It contains a loop that iterates through the listed pages.

Within each iteration of the loop, there is a page object upon which you can add the code you already have to get the attribute.
madesimplemedia replied on at Permalink Reply
madesimplemedia
Got it working, thank you very much Jon!! :)