Get page attribute in page list
Permalink 2 users found helpful
Hi!
I'm new new to Concrete, and my PHP are not even close to CSS and PHP :).
What I'm trying to do is printing the content of an attribute in my custom Page List template.
The attribute will be used on the mother page of the pages looped thru by Page List, so I guess I need to know how I can make the attribute global, so that it can be printed before the foreach function in Page List template.
Basicly, how I can display the content of any attributes in my Page Attributes on any given page?
Best regards from Norway!
I'm new new to Concrete, and my PHP are not even close to CSS and PHP :).
What I'm trying to do is printing the content of an attribute in my custom Page List template.
The attribute will be used on the mother page of the pages looped thru by Page List, so I guess I need to know how I can make the attribute global, so that it can be printed before the foreach function in Page List template.
Basicly, how I can display the content of any attributes in my Page Attributes on any given page?
Best regards from Norway!
Check this pagehttp://www.concrete5.org/documentation/how-tos/designers/styling-th... you might find this cheat sheet helpful too:http://www.weblicating.com/c5/cheat-sheet/...
I think I'm trying to do the same thing but I also can't figure out how to get it to work.
pvernaglia:
I read your tutorial, and it was very helpful, but I can't get it to work the way I want it to.
I want to have a page list template that will display custom attributes of the child pages. I was able to get the page_thumbnail attribute to display, but I can't get two other custom attributes to display: full_name and job_tile
here is my new template file called "thumbnail_view":
pvernaglia:
I read your tutorial, and it was very helpful, but I can't get it to work the way I want it to.
I want to have a page list template that will display custom attributes of the child pages. I was able to get the page_thumbnail attribute to display, but I can't get two other custom attributes to display: full_name and job_tile
here is my new template file called "thumbnail_view":
<?php defined('C5_EXECUTE') or die("Access Denied."); $textHelper = Loader::helper("text"); // now that we're in the specialized content file for this block type, // we'll include this block type's class, and pass the block to it, and get // the content if (count($cArray) > 0) { ?> <div class="ccm-page-list"> <?php for ($i = 0; $i < count($cArray); $i++ ) { $cobj = $cArray[$i]; $target = $cobj->getAttribute('nav_target'); if ($cobj->getCollectionPointerExternalLink() != '') { if ($cobj->openCollectionPointerExternalLinkInNewWindow()) { $target = "_blank";
Viewing 15 lines of 56 lines. View entire code block.
pvernaglia:
I created a new page type that displays various attributes. Most of it works great using the tricks on your second link. Thanks!
The only thing I'm struggling with now is only displaying an attribute if it has a value. I tried the code you provide athttp://www.weblicating.com/doku/doku.php/cheatsheet#test_that_a_val...
I replaced "Do Something here" with the code to display the attribute. I also want to display a field label immediately before the attribute value, so I added some HTML. The final code I used looks like this:
When I load that page, I get a 500 error. I removed my HTML code for displaying the field value thinking that was causing a problem but I still get the 500 error. Any idea what I'm doing wrong?
I created a new page type that displays various attributes. Most of it works great using the tricks on your second link. Thanks!
The only thing I'm struggling with now is only displaying an attribute if it has a value. I tried the code you provide athttp://www.weblicating.com/doku/doku.php/cheatsheet#test_that_a_val...
<?php if ($c->getCollectionAttributeValue(attribute_hande)) { Do Something Here; } ?>
I replaced "Do Something here" with the code to display the attribute. I also want to display a field label immediately before the attribute value, so I added some HTML. The final code I used looks like this:
<?php <?php if ($c->getCollectionAttributeValue('additional_authors')) { <p><strong>Additional Authors</strong>: <?php echo $c->getCollectionAttributeValue('additional_authors') ?></p>; }
When I load that page, I get a 500 error. I removed my HTML code for displaying the field value thinking that was causing a problem but I still get the 500 error. Any idea what I'm doing wrong?
Figured it out. (1) I needed to enclose HTML code in quotes; (2) I had misplaced colons and braces.
Thanks for your reply! The Cheat Sheet is helpfull, but it does not help directly with my problem. I will try to explain it more in detail:
I have a page list that displays the pages of "News"
News
- News 1
- News 2
Thru the page list template I can easily access attributes in from "News 1" and "News 2", but I need to access an attribute from the mother page "News".
The reason for this is that I want to be able to add a header to the page lists, and that the header text can be edited in page properties by adding my Page Attribute.
I have a page list that displays the pages of "News"
News
- News 1
- News 2
Thru the page list template I can easily access attributes in from "News 1" and "News 2", but I need to access an attribute from the mother page "News".
The reason for this is that I want to be able to add a header to the page lists, and that the header text can be edited in page properties by adding my Page Attribute.
This is the top of my current Page List template. I'm trying to display the attribute "block_header" from the "News" page.
<?php defined('C5_EXECUTE') or die("Access Denied."); $rssUrl = $showRss ? $controller->getRssUrl($b) : ''; $th = Loader::helper('text'); //$ih = Loader::helper('image'); //<--uncomment this line if displaying image attributes (see below) //Note that $nh (navigation helper) is already loaded for us by the controller (for legacy reasons) ?> <div class="ccm-page-list"> <div class="block_01_header"> <?php echo $cobj->getCollectionAttributeValue('block_header') ?> </div> <?php foreach ($pages as $page):
Or perhaps the easiest way of doing what i want is to make a template to the HTML or content block, so that the user only adds the header text. Issue is that i don't want the user to have define the text as <h2>, but let a template do that.