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.

All other Modules /

Discuss all other Modules here.

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

Content outside $Layout


Go to End


5 Posts   1853 Views

Avatar
richardus

Community Member, 6 Posts

19 October 2009 at 11:28pm

Hello,

please help me. How Can I place content to template outside $Layout? I want place other content from structure.

Thanks,

Richard

Avatar
socks

Community Member, 191 Posts

20 October 2009 at 7:39am

Not sure if I'm understanding your problem, please elaborate.

templates/Page.ss
This should contain code that's on every page of your site (header, footer, main navigation). If you need to pull fields from the CMS of a specific page

<% control Page(my-page) %>
     $Content
<% end_control %>

http://doc.silverstripe.org/doku.php?id=built-in-page-controls&s=page%20controls

Avatar
richardus

Community Member, 6 Posts

20 October 2009 at 8:09pm

Hello,

I want place to outside $content tag other content (not the main content) eg. contact information so that was always displayed on each page.

Thank You very much,

Richard

Avatar
socks

Community Member, 191 Posts

20 October 2009 at 8:30pm

Edited: 20/10/2009 8:34pm

So you have Contact Info that needs to go on every single page of your site.

In the CMS, if it's for every page, I usually make a new tab on the Home page (other people may do it differently). I did this for my footer (See screenshot).

HomePage.php

class HomePage extends Page {
    static $db = array(
	'Footer' => 'HTMLText'
    ); 

   function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab('Root.Content.Footer', new HTMLEditorField('Footer', 'Content')); 

		return $fields;
    }
}

Page.ss (templates/Page.ss) not templates/Layout/Page.ss

.....
<div id="content">
	$Layout
</div>   
<div id="footer">
	<% control Page(home) %>
		$Footer
	<% end_control %>  
</div>
.....

Attached Files
Avatar
UncleCheese

Forum Moderator, 4102 Posts

21 October 2009 at 2:21am

Edited: 21/10/2009 2:22am

That's the best way to do it is to put the field on your HomePage object. I'm not a big fan of control Page(home), though, because if the URLSegment ever changes, you're hosed. I usually write a function for it.

return DataObject::get_one("HomePage")->ContactInfo;

Also, if you're looking to have different content on every page, you can put that in your Page class. If you had the field ContactInfo in your $db array for Page, you could put $ContactInfo anywhere on your template -- within $Layout or outside of it.