Read More show or not show automatically

Permalink Browser Info Environment
In some cases I am looking at "answers" that are short enough to be in the initial click on and the "read more" field is then left blank. However, when displayed on the page, the read more is there and of course links to a blank page. If I wanted to go about making this dynamic, what DB field/value would I need to check in order to have the "read more" not display if the field was blank?

Type: Discussion
Status: New
plschneide
View Replies:
plschneide replied on at Permalink Reply
plschneide
For anyone who is looking to do this. I made a change about line 23 or so - of the view.php file in the blocs/page_list/templates/example_faq_page/view.php file

<?php
//Paul Mod
if ($cobj->getCollectionAttributeValue('exclude_nav') == 0) { ?>
<a href="<?php echo $nh->getLinkToCollection($cobj)?>" style="font-weight: bold">Read More &gt;</a>
<?php } ?>

Basically it checks to see if you have the "exclude from Nav" option and then doesn't display the more unless you do.
ratstew replied on at Permalink Reply
ratstew
Thank you very much for this!
Would it be possible to check if the "Full Answer" is missing and if so remove the "Read More"?
Just starting out with objective php and c5 so not sure if this is possible.
MattWaters replied on at Permalink Reply
MattWaters
I think Paul's approach is on the right track.

Looking at how this block works, each faq question is created as its own page. The "short answer" data is stored in that page's description.

So if you're building a faq that has questions that only require short answers, you'll naturally want to hide these "blank" pages from navigation (otherwise it would be confusing). So Paul's excluded them from navs, then he uses that php if statement to check for the exclude_nav attribute to see whether or not to include the "Read more" link.

If you don't want to use the exclude_nav attribute for some reason, you could create your own custom attribute. Check out this how-to:

http://www.concrete5.org/documentation/how-tos/developers/create-a-...
ratstew replied on at Permalink Reply
ratstew
I see your point and completely agree with the reasoning behind it. What i wanted to avoid though was for content writers to have to go into the sitemap and change attributes to show/hide the read more, would it be possible to add this control into the FAQ section of the site?
I would like to be able to get support stuff their own login with permission to change only the FAQ further down the road so then this functionality will need to be implemented.
plschneide replied on at Permalink Reply
plschneide
Having had to do alterations myself (that are okay), I agree it would be REALLY nice if the "display" of the more link auto showed or didn't based on if there was any additional content written.

Paul

-----Original Message-----
From: Concrete5 Community [mailto:discussions@concretecms.com]
Sent: Thursday, March 17, 2011 2:36 AM
To: pauls@studio5d.com
Subject: Read More show or not show automatically: Read More show or not show automatically
MattWaters replied on at Permalink Reply
MattWaters
I hacked this together a moment ago in blocks/page_list/templates/example_faq_page_list/view.php. It fetches the first Main area block content from the faq entry page (which is where your "Read More" stuff gets put) and spits out the link if its length isn't 0.

<div class="faq-entry-description">
<?php  echo $cobj->getCollectionDescription()?>
<?php 
    $blocks = $cobj->getBlocks('Main');
    $b = $blocks[0];
    $bi = $b->getInstance();
    $content = $bi->getContent();
    if (strlen($content) != 0) { ?>
        <a href="<?php  echo $nh->getLinkToCollection($cobj)?>" style="font-weight: bold">Read More &gt;</a>
    <?php } ?>
</div>


There might be a better way of doing this-- I swiped the code from a related solution and tinkered with it. But it seems to work for me...
plschneide replied on at Permalink Reply
plschneide
Thanks Matt,

This is exactly what I wanted to do originally, but wasn't sure of the syntax with concrete objects. Works great- but one thing to note, if you add some blocks to a page and later change your mind, and delete them, you might get an error on the "FAQ" page. I ran into this problem - adding a blank block to the offending FAQ page solved the problem.

Paul

-----Original Message-----
From: Concrete5 Community [mailto:discussions@concretecms.com]
Sent: Thursday, March 17, 2011 3:09 PM
To: pauls@studio5d.com
Subject: Read More show or not show automatically: Read More show or not show automatically
MattWaters replied on at Permalink Reply
MattWaters
Ah, nice catch. I was just putting it through its paces. That's a good test. Seems like all entries on the FAQ page don't work if you kill a main block on any one entry.

I'm sure there's something better that we could test for instead of plain old 0...0 or undefined?
plschneide replied on at Permalink Reply
plschneide
Yeah maybe undefined - not sure how it treats a block that was there but removed. It works fine if you don't add anything or if you do, you don't remove it. Some weird positioning... maybe you would need to loop through all active blocks on the page....?



-----Original Message-----
From: Concrete5 Community [mailto:discussions@concretecms.com]
Sent: Thursday, March 17, 2011 5:30 PM
To: pauls@studio5d.com
Subject: Read More show or not show automatically: Read More show or not show automatically
MattWaters replied on at Permalink Reply
MattWaters
Yeah, I'm not sure, but I think we're still on the right track. I guess you'd need to think about how your site editors / contributors would be adding and revising content in order to come up with a "fool-proof" solution.
plschneide replied on at Permalink Reply
plschneide
Yeah for the site in question - this solution is just fine (for me).

-----Original Message-----
From: Concrete5 Community [mailto:discussions@concretecms.com]
Sent: Friday, March 18, 2011 11:42 AM
To: pauls@studio5d.com
Subject: Read More show or not show automatically: Read More show or not show automatically
lenrsmith replied on at Permalink Reply
lenrsmith
Hey guys,

I worked on this little issue, today, and came up with what I think is a better solution. I created a custom attribute, added it to the FAQ Add/Edit form, and added a check for it in the view php. Here are the details:

1. Create a new custom attribute under Pages and Themes>Attributes called 'faq_showfullanswer'.
a. Under 'Add Page Attribute' select 'Checkbox' for the 'Choose Attribute Type' dropdown and click 'Go'.
b. Enter 'faq_showfullanswer' for 'Handle' and 'Show Full Answer?' for 'Name'
c. Click 'Add'
2. Add the new attribute to the FAQ Add/Edit Form
a. Open packages/example_faq/single_pages/dashboard/example_faq/view.php
b. Around line 60 or so, between the code for faqDate and the Full Answer add the following:
<?php
     Loader::model("attribute/categories/collection");
     $akt = CollectionAttributeKey::getByHandle('faq_showfullanswer');
      if (is_object($faq))  {
          $tvalue = $faq->getAttributeValueObject($akt);
      }
?>
<strong><?php echo $akt->render('label'); ?></strong>
<div><?php echo $akt->render('form', $tvalue, true); ?></div>
<br/>

You could add it a little lower in the 'faq_attributes' div element if you prefer.
c. Save the view.php.
3. Add code to save the attribute to the controller
a. Open packages/example_faq/controllers/dashboard/example_faq/controller.php
b. Add the following code at the end of the saveData function:
$cak = CollectionAttributeKey::getByHandle('faq_showfullanswer');
$cak->saveAttributeForm($p);

c. Save controller.php.
4. Add code to view.php of the custom template for the page list block
a. Open packages/example_faq/blocks/page_list/templates/example_faq_page_list/view.php
b. Insert the following code in place of the "Read More' code around line 24:
<?php
     if ($cobj->getCollectionAttributeValue('faq_showfullanswer') == 1) {
?>
     <a href="<?php  echo $nh->getLinkToCollection($cobj)?>" style="font-weight: bold">Read More &gt;</a>
<?php } ?>

I hope that's clear and that it helps. It works for me, anyway. You could by-pass creating the new custom attribute and just use the 'Exclude from Nav' attribute on your form. I prefer the new attribute as it makes more semantic sense for the user.
Huckleberry replied on at Permalink Reply
Huckleberry
Thanks lenrsmith!
This works beautifully! Exactly what I needed. Only thing better would be if it could do this dynamically. But your solution works like a charm.
One note I'd make in your directions, which are quite thorough btw, is in step 4, but sure not to delete this line:
echo $cobj->getCollectionDescription();
[code]
The updated section should look like this:
[code]
<div class="faq-entry-description">
         <?php
          echo $cobj->getCollectionDescription();
     if ($cobj->getCollectionAttributeValue('faq_showfullanswer') == 1) {
?>
     <a href="<?php  echo $nh->getLinkToCollection($cobj)?>" style="font-weight: bold">Read More &gt;</a>
<?php } ?>
      </div>


That was the only part I saw that wasn't clear, and I accidentally deleted my short answers b/c of it, or rather made them not show. It was an easy fix though.
Thanks for the thoughtful fix!

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.