Jump to:

23380 Posts in 18311 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » show article with an option checked

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: 877 Views
  • cbartgu
    Avatar
    Community Member
    12 Posts

    show article with an option checked Link to this post

    Does anyone know how to show an article which has a boolen option ticked, so if you had to pick a random article that it about a certain subject to show on the front page.

    I wanted to use the <% control %> method but cannot find a tutorial on how to do it,

    cbartgu,

  • banal
    Avatar
    Community Member
    901 Posts

    Re: show article with an option checked Link to this post

    The easiest way would be to create a custom method that will return a random article.
    Example:

    // put this in your Page_Controller
    public function RandomArticle(){
       return DataObject::get_one('ArticlePage', 'Option = 1', true, 'RAND()');
    }

    Where 'ArticlePage' is the name of your Article Page Class and 'Option = 1' would be the WHERE statement.
    Then in the Template you could write:

    <% control RandomArticle %>
    ... access members of the ArticlePage here ...
    <% end_control %>

    877 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.