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.

Customising the CMS

Template Syntax for specific Dataobject entry


Reply

3 Posts   1296 Views

Avatar
Anatol

22 June 2009 at 4:33pm 126 Posts

Hi all,

I'm setting up a website with the brilliant [url=http://silverstripe.org/dataobjectmanager-module/]Dataobject Manager[/url] (but I don't think the question is specific to that). To get only the first (second, third) entry I use this template syntax:

<% control MediaAssets %>
   <% if Pos=1 %>
      $displayMediaAsset
   <% end_if %>
<% end_control %>

Is there any better way to get just a specific entry than this method without the <% if %> block?

I tried $displayMediaAsset.1 , $displayMediaAsset(1) , control MediaAssets(1) , control MediaAssets.1 but all of that doesn't work.

It's OK if I use the conditional if but I'm hoping there's a shorter solution.

Cheers!
Anatol

Avatar
Hamish

22 June 2009 at 5:00pm (Last edited: 22 June 2009 5:01pm), Community Member, 712 Posts

Yep - ".First":

<% control MediaAssets.First %>
   $displayMediaAsset
<% end_control %>

Avatar
Anatol

22 June 2009 at 5:22pm 126 Posts

Hi Hamish,

thank you for the reply. Yes, that works for the first Dataobject. What I'm looking for is something like

<% control MediaAssets.Pos(1) %>
   $displayMediaAsset
<% end_control %>

So the Position could be Pos(1), or Pos(2) or Pos(3) etc. But the code above doesn't do anything. What's the best way to write this?

Cheers!
Anatol