Which vars do you mean exactly?
e.g.
control Menu(1) would be something like this:
foreach ($this->Menu(1) as $item) {
if ($item->LinkOrSection() == 'section' && $item->Children()) {
// etc. pp.
}
}
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.
Which vars do you mean exactly?
e.g.
control Menu(1) would be something like this:
foreach ($this->Menu(1) as $item) {
if ($item->LinkOrSection() == 'section' && $item->Children()) {
// etc. pp.
}
}
Everytime I use "$this->Menu(1)" I get a Server Error.
All I want is to find out if the current page have children. But if I'm on home, the 4 links don't count.
Like this:
$page = $this;
$pages = array();
if($page->ShowInMenus || ($page->ID == $this->ID)) {
$pages[] = $page;
}
$Parent = $pages[0]->record["ParentID"];
if($Parent != NULL && $Parent != 0 && !empty($Parent)) {
$output = true;
}
Thats just reversed. There I have a "ParentID", poorly I don't have "ChildrenID".
Everytime I use "$this->Menu(1)" I get a Server Error.
Please set you environment to 'dev' mode. Then we could get a proper error message.
Director:
environment_type: 'dev'
I really don't see what you trying to accomplish with your code. I've abbreviated your code to something simple:
if (!empty($this->ParentID)) {
$output = true;
}
There I have a "ParentID", poorly I don't have "ChildrenID".
You don't have a ChildrenID, but an ID. SilverStripe will do the rest for you.
e.g. if we have two pages:
- ParentPage // ID = 12
- ChildPage // ID = 13
foreach($ParentPage->Children() as $child) {
echo $child->ID // 13
echo $child->ParentID // 12
}
$parent = $ChildPage->Parent();
echo $parent->ID // 12
All I want is to find out if the current page have children. But if I'm on home, the 4 links don't count.
// if the current page have children ...
if ($this->Children()) {
$output = true;
}
// But if I'm on home, the 4 links don't count
if ($this->URLSegment == 'home') {
$output = false;
}
Well, sometimes I'm really stupid. Thats exactly what I'm searching for.
Just a little thing. If there's no children anymore then $output should be false. But thats the point where I don't know how I should do this.
If there's no children anymore then $output should be false. But thats the point, I don't know how I should do this.
The condition "<% if HaveChilden %>open<% end_if %>" will only be executed if HaveChilden returns true. But this will only do so if current page has children.
// default state
$output = false;
// if the current page have children ...
// ... else $output keeps being false
if ($this->Children()->exists()) {
$output = true;
}
// But if I'm on home, the 4 links don't count
// ... else $output is either true if it $this has children or keeps being false
if ($this->URLSegment == 'home') {
$output = false;
}
return $output // true or false
edit
I've made an error. "if ($this->Children())" will always return true, please use "if ($this->Children()->exists())" instead.
Thank you alot! That's exactly what I wanted. (: