5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1192 Views |
-
Show CMS field only on top level pages

21 January 2010 at 8:57am
HI, I have a site where each top level page has data associated which controls pages under it (styles etc). I'm looking for a way to specify a field in Page.php but only have it show up in the CMS if it is a top level page.....any ideas out here?
-
Re: Show CMS field only on top level pages

21 January 2010 at 11:39am
Well you could have a condition in the getCMSFields - if($this->ParentID == 0) since if its a top level page, it has no parent
. -
Re: Show CMS field only on top level pages

21 January 2010 at 11:53am Last edited: 21 January 2010 11:53am
Great thanks Will.....
the other issue Im having with this is retreiving an Image from the top level. ie I have the following function in Page_Controller:
function getSubNavBg() {
return $this->Level(1)->SectionNavImg;
}where SectionNavImg is an Image
and in my template I'm trying to set a background image on a sub nav for a section using eg:
<style>
ul#SubNav {background:url($getSubNavBg.Filename) }
</style>but it will not bring the filename through....am I missing something blindingly obvious?
-
Re: Show CMS field only on top level pages

21 January 2010 at 12:27pm
Try
ul#SubNav {background:url({$SubNavBg.Filename}) }
If that doesn't work make sure $SubNavBg exists. Try a <% debug SubNavBg %> and see what it says.
-
Re: Show CMS field only on top level pages

21 January 2010 at 1:57pm Last edited: 21 January 2010 1:59pm
Hi, doesn't seem to be any JOy here...I'll list all the relevant code in case we've missed something:
Page.php
class Page extends SiteTree {
public static $db = array(
'SectionColour' => 'Text',
'SectionHighlightColour' => 'Text'
);
public static $has_one = array(
'SectionNavImg' => 'Image'
);
function getCMSFields() {
$fields = parent::getCMSFields();
if($this->ParentID == 0){
$fields->addFieldToTab('Root.Content.Theme', new ColorField('SectionColour', 'Section Colour'));
$fields->addFieldToTab('Root.Content.Theme', new ColorField('SectionHighlightColour', 'Section Highlight Colour'));
$fields->addFieldToTab('Root.Content.Theme', new ImageField('SectionNavImg'));
}
return $fields;
}
}class Page_Controller extends ContentController {
public function init() {
parent::init();
}
function SectionColour() {
return $this->Level(1)->SectionColour;
}
function HiglightColour() {
return $this->Level(1)->SectionHighlightColour;
}
function SubNavBg() {
return $this->Level(1)->SectionNavImg;
}
}In my template $SectionColour returns the correct value from the top level page, but the Image ( using $SubNavBg.Filename ) will just not come through.......
-
Re: Show CMS field only on top level pages

21 January 2010 at 2:28pm
$this->Level(1)->SectionNavImg
Probably because the image is a relationship you need to return the object so try either
return $this->Level(1)->SectionNavImg();
or
return $this->Level(1)->dbObject('SectionNavImg');
The first one should work though.
-
Re: Show CMS field only on top level pages

21 January 2010 at 2:37pm
Great thanks Will!
return $this->Level(1)->SectionNavImg(); worksknew it would be something simple
| 1192 Views | ||
|
Page:
1
|
Go to Top |

