10375 Posts in 2190 Topics by 1707 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1126 Views |
-
Content outside $Layout

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
-
Re: Content outside $Layout

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 -
Re: Content outside $Layout

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
-
Re: Content outside $Layout

20 October 2009 at 8:30pm Last edited: 20 October 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>
..... -
Re: Content outside $Layout

21 October 2009 at 2:21am Last edited: 21 October 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.
| 1126 Views | ||
|
Page:
1
|
Go to Top |


