Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

1598 Posts in 399 Topics by 403 members

Template Questions

SilverStripe Forums » Template Questions » NoHTML in LimitWordCount Summary

Page: 1
Go to End
Author Topic: NoHTML in LimitWordCount Summary 713 Views
  • Andrew Houle
    avatar
    Community Member
    85 posts

    NoHTML in LimitWordCount Summary Link to this post

    I think this should be rather easy, but I can't find a simple solution to this. Basically I just want to print a summary of about 50 words as plain text. However, asterisks are being substituted where bold text is. This thread seems to be headed in the right direction: http://silverstripe.org/customising-the-cms/show/255639#post255639 but the ticket explaining the fix is not working.

    Has anyone gotten this to work correctly? What should go in my controller, and what should go in my template?

    I have something like this in my controller...

    function ArticleSummary() {
          $ac = $this->obj('ArticleContent')->NoHTML();
          return $ac->LimitWordCount(50);
       }

    And this in my template...

    <p>$ArticleSummary</p>

    I know that logic has plenty of flaws, but I wanted to give a starting point. Thanks in advance for you help.

  • aram
    avatar
    Community Member
    485 posts

    Re: NoHTML in LimitWordCount Summary Link to this post

    Hi Andrew

    I ended up doing something this with regular php as I wanted a charachter limit, it looked something like this:

    function LimitWords($CharLimit = 500){

    $NoHTML = strip_tags($this->Content);

    return substr($NoHTML, $CharLimit);

    }


    Shouldnt be too much trouble to adapt it for woud count instead of chars.

  • Andrew Houle
    avatar
    Community Member
    85 posts

    Re: NoHTML in LimitWordCount Summary Link to this post

    HI Aram,

    Thanks for your help. I'm still quite a noob at most things programming so forgive me if this is a dumb question. The Article summaries that I want to pull minus all the HTML issues are coming from two url params of IssueID and CategoryID. So I have a function like this...

    function show() {
          $articles = DataObject::get("Article", "ParentID = " . $this->urlParams['ID'] . " AND CategoryID = " . $this->urlParams['OtherID']);
          if ($articles->Count() == 1) {
             Director::redirect($articles->First()->Link());
          }
          else {
             return $this->customise(array('Articles' => $articles))->renderWith(array('IssueHolder_show','Page'));
          }
       }

    Then in my template I pull the info using something like...

    <% control Articles %>
    $ArticleContent.LimitWordCountPlainText(60)
    <% end_control %>

    I would like to sub out $ArticleContent.LimitWordCountPlainText(60) with $ArticleBlurb which is a function like how you described. My question is how to interact with my show() function? Hopefully that makes sense, thanks in advance for your help!

  • aram
    avatar
    Community Member
    485 posts

    Re: NoHTML in LimitWordCount Summary Link to this post

    Hi Andrew

    You should be able to put the ArticleBlurb() function in your ArticlePage model and then call it within your <% control Articles %> without affecting the show() stuff.

    As long as you are in the context of an article, $ArticleBlurb should return the correct stuff in the same way as $Content would.

    Hope that helps

  • Andrew Houle
    avatar
    Community Member
    85 posts

    Re: NoHTML in LimitWordCount Summary Link to this post

    I got it to work but It's not limiting the characters, but it is stripping the html... weird. Oh well, I've got a different workaround that will do the trick. Thanks for you help.

  • Andrew Houle
    avatar
    Community Member
    85 posts

    Re: NoHTML in LimitWordCount Summary Link to this post

    I figured out why the code wasn't returning the first x amount of characters. So for completion sake, maybe this will help someone else; here is an example of the code:

    function ArticleSummary($Char=240) {
       $NoHTML = strip_tags($this->ArticleContent);
       return substr($NoHTML,null,$Char);
    }

    I don't think the substr function will work properly without taking in that second parameter, which btw could be use to start at a different place.

    713 Views
Page: 1
Go to Top

Currently Online: jondbaker

Welcome to our latest member: fearofbuttons

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

Comments on this website? Please give feedback.