Jump to:

3395 Posts in 977 Topics by 853 members

Template Questions

SilverStripe Forums » Template Questions » Display custom DataField in Templates inside DataObjectSets

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

Page: 1
Go to End
Author Topic: 1097 Views
  • Ironcheese
    Avatar
    Community Member
    33 Posts

    Display custom DataField in Templates inside DataObjectSets Link to this post

    Hello,

    i have several custom DataFields inside my Page. Inside the templates i can access the default fields by just naming them. Like "$Title" "$MenuTitle" etc.

    this works inside Control Loops aswell.

    What doesnt work is the same trick with my custom datafields. As soon my pages come inside a dataobjectset it seems the templates cant access my custom fields.

    So if i try something like:

    <% control Children %>
    <a href="$Link" title="$MetaDescription">$myCustomTitle</a>
    <% end_control %>


    it does not work! As soon i access the page directly like:

    <% control Page(mypage) %>
    <a href="$Link" title="$MetaDescription">$myCustomTitle</a>
    <% end_control %>
    it works....

    Probably its somethin trivial....

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Display custom DataField in Templates inside DataObjectSets Link to this post

    Is myCustomTitle a method on your controller class or on the model? If its on the controller you may not have access to it in a dataobjectset like children as it only stores the model object of the page. To fix this simply move the function from your controller to the model.

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