Hello,
I've created a CMS Sidebar tab in Page.php with the following fields: SidebarTitle, SidebarContent, PhotoComment and Photo. I would like to create a specific "if block and control" function that would output the Sidebar.ss template only if there is any content added to any of the fields in the CMS.
How would I create a function for a tab? I know how to do if the Sidebar is a pagetype (e.g., public function GetSidebar(){
return DataObject::get_one("Sidebar");} but not for an array of fields in a custom tab,
This is an example of the Sidebar.ss That I would like to create based on the Sidebar tab:
<% if GetSidebar %>
<% control GetSidebar %>
<div id="Sidebar" class="typography">
<h3>$SidebarTitle</h3>
<ul >
<li>$Photo.SetWidth(180)</li>
<li>$PhotoComment</li>
<li>$SidebarContent</li>
</ul>
</div>
<% end_control %>
<% end_if %>
********************************
This is the relevant code from my Page.php:
class Page extends SiteTree {
Public static $db = array(
'SidebarTitle' => 'Varchar(255)',
'SidebarContent' => 'HTMLText',
'PhotoComment' => 'Varchar(255)',
);
static $has_one = array(
'Photo' => 'Image',
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Sidebar", new TextField("SidebarTitle", "Sidebar Item Title"));
$fields->addFieldToTab("Root.Content.Sidebar", new ImageField('Photo'));
$fields->addFieldToTab("Root.Content.Sidebar", new TextField("PhotoComment", "Photo comment"));
$fields->addFieldToTab("Root.Content.Sidebar", new HtmlEditorField("SidebarContent", "Sidebar Content"));
return $fields;
}
Thanks,
Sam Miller