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.

Template Questions /

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

Display custom DataField in Templates inside DataObjectSets


Go to End


2 Posts   1756 Views

Avatar
Ironcheese

Community Member, 36 Posts

10 July 2010 at 11:42am

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

Avatar
Willr

Forum Moderator, 5523 Posts

10 July 2010 at 4:22pm

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.