Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » How to only show a more link if there's actually more content?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1118 Views
  • steffik
    Avatar
    Community Member
    15 Posts

    How to only show a more link if there's actually more content? Link to this post

    I'm stuck with a little programming problem and don't know how to proceed.

    I only want to show a more link on a news if there is actually more content than just the first paragraph. Something like
    <% if Content > Content.FirstParagraph %>
    but as i know that the templating language doesn't support comparisons just jet, i tried to write this in my NewsList Controller, but i think my function never gets called, so i wonder if i'm making anything wrong?

       
       function HasMoreContent() {
          if ($this->obj('Content')->FirstParagraph()
             && $this->Content > $this->obj('Content')->FirstParagraph()) {
             return true;
             } else {
             return false;
          }
       }

    and in the template:

    <% if Content %>
    <% if HasMoreContent %>
       <a href="$Link" title="Mehr &uuml;ber &quot;{$Title}&quot;"> &gt;&gt; mehr</a>
    <% end_if %>
    <% end_if %>

    i also tried something like this, just to see if anything gets called at all

    function HasMoreContent() {
       print "test";
       return "Test";
    }

    and in the template:

    $HasMoreContent

    Any hints on how to proceed would be greatly appreciated.

  • JonoM
    Avatar
    Community Member
    103 Posts

    Re: How to only show a more link if there's actually more content? Link to this post

    Regarding your function not getting called - I think it might be a context/scope thing. I'm guessing you have something like a NewsList page type and a NewsArticle page type? In that case I think the HasMoreContent() function should be on your NewsArticle controller instead of your NewsList controller.

    1118 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.