Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

show article with an option checked


Go to End


2 Posts   1443 Views

Avatar
cbartgu

Community Member, 12 Posts

17 June 2009 at 11:12pm

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,

Avatar
bummzack

Community Member, 904 Posts

18 June 2009 at 2:47am

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 %>