Retrieving some DataObjects in template without php getter

When trying to get e.g. the lastest blog posts in your template you normally create a getter for theese in php like:

    function getLastestBlogPosts($limit=3, $offset=0) {
      return BlogPost::get()->limit($limit, $offset);

and in template something like

<% loop $LatestBlogPosts %>
<% end_loop %>

While this works very good, you always need to touch your php codebase when you want to grab a DataList. But SilverStripe has a nice feature, to get any (simple) DataList directly in your template, the $List helper:

<% loop $List('BlogPost').Limit(3) %>
<% end_loop %>

which will get you the latest 3 blog posts (assuming that BlogPost's $default_sort is set properly).

See also:


Rate this post (2 rating(s))

Post your comment


No one has commented on this page yet.

RSS feed for comments on this page | RSS feed for all comments