Page that shows only summary of pages with an attribute

Permalink
This might be rudimentary or not even possible, but i wish to create several pages that have an attribute "highlight" then make a parent page that shows only the content in the <summary> tag of only pages with the attribute "highlight".

Can anyone point me in the right direction?

 
mkly replied on at Permalink Reply
mkly
Hmmm... I'm having a little trouble understanding exactly what you are looking for.

So you want a Page Attribute named "highlight"

Then you want a Page to show all of it's children pages' with a custom Page Attribute named "Summary".

Or are you looking for the parent page to pull out the part within the HTML5 tag <summary>?

Creating a Page Attribute named "Summary" would certainly be the simplest way. Then you could just get all of the parent pages child pages, filter by the highlight attribute and only display the summary attribute.
<?php
  //First we get the current page
  $parent = Page::getCurrentPage();
  Loader::model('page_list');
  $pl = new PageList;
  //Then we use the current page to filter chidren
  $pl->filterByParentID($parent->getCollectionID());
  //We filter children by the new attribute
  $pl->filterByHighlight(true);
  //We get the pages
  $pages = $pl->get();
?>
<?php /*Now we output the "summary" page attribute */ ?>
<?php if(!empty($pages)): ?>
  <?php foreach($pages as $page): ?>


Otherwise, I'm not sure. It would have to do with getting child page outputs and then extracting the summary tag via regex or whatever. But I really don't know how you could do that.
Casemon replied on at Permalink Reply
Thanks, i should have been more clear and broken down the question into 2 parts.

1st part) want a page to only show content from child pages that have a specific attribute.

Haven't tried it, but think your example does just that! Thank you :)

2nd part) wish to show only portion of the child page, not all of the content. Similar to how Wordpress has the 'more' tag for the blog, wish to isolate a portion of a page (with some tag? i used summary after a quick search of the html spec, but didn't realize this tag is not supported by any browser as of yet :| ), then use that to only show that portion in the parent (referenced in the 1st part).
mkly replied on at Permalink Reply
mkly
I was afraid of that. Ok, well part of this issue is that C5 is more modular than WP so it may be difficult to decide what constitutes as the block to actually truncate but....
<?php
  //First we get the current page
  $parent = Page::getCurrentPage();
  Loader::model('page_list');
  $pl = new PageList;
  //Then we use the current page to filter chidren
  $pl->filterByParentID($parent->getCollectionID());
  //We filter children by the new attribute
  $pl->filterByHighlight(true);
  //We get the pages
  $pages = $pl->get();
  //Now we get each block of each page
  if(!empty($pages)) {
    foreach($pages as $page) {
      //I'm going to assume we're getting from the Main Area

As you can see we have to make a big assumption here. That the content you are looking for is going to be in "Main" or where ever we specify. Also that the content with be the _only_ thing in there. We could also just grab the first block in "Main" or something creative like that. But I can't think of a method that would not need to make some assumptions.

EDIT: Updated to @jordanlev's suggestion below.
Casemon replied on at Permalink Reply
Thanks, that sounds like what I'm after.

Though I'll have to look into blocks in this context, think i'll need to make a custom page type and include a special block for this?

Thing is, I don't want the excerpted content to be shown when the user displays the (child) page by itself.

So basically, want a parent page that contains only specific content of the child pages, but the child pages don't show that content if viewed directly.

The idea in my mind seems very common (define & show page excerpts)... am surprised have to jump through all these hoops to enact it!
mkly replied on at Permalink Reply
mkly
If you don't want the content displayed on the child page I would just create a Page Attribute named "Summary" and edit it through the Page Properties. That won't be visible on the page and you can pull it up from the parent page. Like in the first code block I sent over.

To display the content I would probably just make a custom block and put that code in it. I don't know if you have made a block before, but it's really quick.
jordanlev replied on at Permalink Reply
jordanlev
I would just use the built-in page "Description" field and a Page List block. What you're asking for here already exists in the system -- just fill in the summary to the "Description" field when you add new pages, then on your top-level page, put a Page List block and check the box to display descriptions, and it will do what you want. No need for custom code!

The hard part is when you want to show content from the actual page as opposed to the description or summary that doesn't appear on the page -- but there are ways to handle this as well. If you're interested in this, check out the free Page List Teasers addon:
http://www.concrete5.org/marketplace/addons/page-list-teasers...
Casemon replied on at Permalink Reply
Yes, had considered Description, but it's text only; have need for rich text, so am using the text-area attribute.

That looks like a cool plugin none-the-less. Thanks for the link! :)
fastcrash replied on at Permalink Reply
fastcrash
did you solve this case?
i want to add rich editor(tinyMCE) in the description page.

is there a way? or another solution if it cannot?
admin replied on at Permalink Reply
Hey Casemon.

Did you ever get this to work? When I display a rich text attribute in a page list it displays the raw HTML, not the stylized text. I can't figure it out. Then again, I know next to nothing about PHP and building in C5.

Thanks!
Casemon replied on at Permalink Reply
Also, small typo error in your updated example:

$btc = $bl->getInstance();
should be:
$btc = $block->getInstance();
Casemon replied on at Permalink Reply
After looking into this, going to go your 1st solution and use a text block Attribute (rich text) and show only that for defining / showing an excerpt.

Thanks for steering me in the right direction :)
mkly replied on at Permalink Reply
mkly
No problem. Good luck.
jordanlev replied on at Permalink Reply
jordanlev
@mkly, you might be interested in this custom page list template I made:
https://github.com/jordanlev/c5_clean_block_templates/blob/master/pa...

...scroll down to about line #79 ("HOW TO DISPLAY ACTUAL PAGE CONTENT"), I have a few examples of different ways this could be achieved. The last one is similar to yours, but it uses $block->btHandle to determine the block type instead of get_class (which I imagine is less efficient because it requires some kind of code reflection). Not saying you're wrong and I'm right, just thought you might be interested to see other examples of code like this.

-Jordan
mkly replied on at Permalink Reply
mkly
That's awesome. btHandle is certainly preferred. Thank you. It's very much appreciated.
Casemon replied on at Permalink Reply
Also, in your example, where does filterByHighlight come from? I don't see that in the concrete5 api.
mkly replied on at Permalink Reply
mkly
Oh sorry. I guess it's magic. Instead of doing filterByAttribute you can just specify the attribute handle in camel case ie filterByMyCustomAttibute.
Casemon replied on at Permalink Reply
That's both handy & confusing :P

I searched for that in the docs and didn't find anything, only:
http://www.concrete5.org/api/Utilities/DatabaseItemList.html#method...

Also, it uses CamelCase but also apparently we have to strip any _ in the handle...

So some_attribute becomes SomeAttribute... (how are we supposed to know that? sheesh)