17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1399 Views |
-
if page control

11 July 2008 at 5:27pm
I added a custom tab to the Page page type. I've got it working using an include in Page.ss. How can I tell it only to show up if there is text in the text field on that tab and if there's not I don't want it to be included at all?
-
Re: if page control

11 July 2008 at 7:24pm Last edited: 11 July 2008 7:25pm
Perhaps you could try something like:
<% if SomeField %>
<% include SomeFile %>
<% end_if %> -
Re: if page control

11 July 2008 at 8:33pm Last edited: 11 July 2008 8:38pm
That did it! Well I had to tweak it a bit but that was what I needed.
Here's what I did so it's documented in case someone else needs to know:
1. I added an "Announcement" tab to Page.php.
class Page extends SiteTree {
static $db = array(
"AnnouncementContent" => "Text",
);function getCMSFields() {
$fields = parent::getCMSFields();$fields->addFieldToTab('Root.Content.Announcement', new TextField('AnnouncementContent'));
return $fields;
}
static $has_one = array(
);
}2. I created Announcement.ss and put in in the includes folder of my theme.
<% control Page(home) %>
<% if AnnouncementContent %>
<div id="announcement">
$AnnouncementContent
</div>
<% end_if %>
<% end_control %>3. I added the include to the appropriate place in Page.ss
Now What would make it better is to be able to remove the tab from all the pages other than Home. But do that without creating a HomePage page type. Home is just a Page page type like all the rest. With the page control in Announcement.ss it will only take the text that's entered in the Announcement tab on the home page. But it would make it less confusing for the user if that tab was only there on the page that it pulls from.
-
Re: if page control

13 July 2008 at 3:37pm
sonicparke-
You're really close! You could try adding an if statement around your addFieldToTab method:
if ('Home' == $this->Title) {
$fields->addFieldToTab( 'Root.Content.Announcement', new TextField( 'AnnouncementContent' ) );
return $fields;
}Depending on what you need, you could also compare that to MenuTitle instead of Title.
Hope that helps!
| 1399 Views | ||
|
Page:
1
|
Go to Top |


