Hello,
please help me. How Can I place content to template outside $Layout? I want place other content from structure.
Thanks,
Richard
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
Hello,
please help me. How Can I place content to template outside $Layout? I want place other content from structure.
Thanks,
Richard
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 %>
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
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>
.....
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.