Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Template Syntax for specific Dataobject entry

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

Page: 1
Go to End
Author Topic: 1273 Views
  • Anatol
    Avatar
    126 Posts

    Template Syntax for specific Dataobject entry Link to this post

    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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Template Syntax for specific Dataobject entry Link to this post

    Yep - ".First":

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

  • Anatol
    Avatar
    126 Posts

    Re: Template Syntax for specific Dataobject entry Link to this post

    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

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