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

[Solved]Display data from dataobject in literalfield template page


Go to End


2 Posts   967 Views

Avatar
voodoochile

Community Member, 52 Posts

4 May 2012 at 3:35pm

Hi All

I need a little help please.
i am trying to display a template page in a tab in the cms and populate it with data from a dataobject,
so far ...
i have created the dataobject, and using modeladmin have setup the tabs to fill out the formdata, and have added a tab with a literalfield that calls a template to display the result. it seems to ignore the control blocks and the $fielddata tags.
and to complicate matters their are several dropdowns that get thier data from several dataobjects.

this page works perfectly in the frontend, however some users will only work in the cms side and need to see the finished form without having to go into the front.

Hope this makes sense

Thanks

Avatar
voodoochile

Community Member, 52 Posts

5 May 2012 at 11:36pm

Edited: 05/05/2012 11:43pm

Hi All

After A long day of searching and pondering and sore eyes i managed to work this out

Here is what i have done.

mysite/code/DataObject.php

	function getData()
	 {
	   if($ViewPage = DataObject::get('DataObject'))  
	       {
	  return $this -> customise(new ArrayData(array())) -> renderWith('ViewPage'); 
	       }
	  }

// CMS fields

                $fields->addFieldToTab('Root.TabName', new LiteralField('Data View', $this->getData()));

This Will Render a Page from a Template into a tab in your dataobject in the cms and populate it with the data from that object.

Note: The template needs to be put into mysite/templates folder and if you create an includes folder the includes should work aswell.

Hope this helps someone in the future