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.

Customising the CMS /

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

Template Syntax for specific Dataobject entry


Go to End


3 Posts   1955 Views

Avatar
Anatol

126 Posts

22 June 2009 at 4:33pm

Hi all,

I'm setting up a website with the brilliant Dataobject Manager (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

Community Member, 712 Posts

22 June 2009 at 5:00pm

Edited: 22/06/2009 5:01pm

Yep - ".First":

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

Avatar
Anatol

126 Posts

22 June 2009 at 5:22pm

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