Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

nested controls: get values from parent

Go to End

4 Posts   2966 Views


Community Member, 173 Posts

6 October 2009 at 10:34am

Edited: 06/10/2009 10:35am

Hi, i am trying to loop through one menu control [Menu(3)]. Within the loop i nested a custom control.

the result shoud look like this:

- item 1.$MenuTitle
item a. (item 1 $Top.Link)
item b. (item 1 $Top.Link)
item c. (item 1 $Top.Link)
- item 2.$MenuTitle
item a. (item 2 $Top.Link)
item b. (item 2 $Top.Link)
item c. (item 2 $Top.Link)
- item 3.$MenuTitle
item a. (item 3 $Top.Link)
item b. (item 3 $Top.Link)
item c. (item 3 $Top.Link)
- item 4.$MenuTitle
item a. (item 4 $Top.Link)
item b. (item 4 $Top.Link)
item c. (item 4 $Top.Link)

The Problem is, that you It will NOT return the additionally joined data (

How can i get the right Data?

P.S.There is another small thing: if you use s.t. like: $Top.Link/show/$ID you will have a double slash, because $Top.Link already contains one "/" (gesundheitswesen//show/6). How can i get rid of it?

Greetings, Carsten.


<div id="banner">
<div class="banner_top">&nbsp;</div>
<div class="banner_inner">
<ul class="menu">
<% control Menu(3) %>
<li class="sublevel1">$MenuTitle
<% control getFirmenforBanner %>
<li class="sublevel2">
<a href="$Top.Link/show/$ID">$Firmenname $URLSegment</a>
<% end_control %>
<% end_control %>
<div class="banner_end">&nbsp;</div>

Page.php (model):

function getFirmenforBanner() {
// Tabelle + Where + Sort + JOIN + LIMIT
$firmen = DataObject::get("Stammdaten", "", "Stammdaten.Firmenname", "", "");
return $firmen;



Community Member, 283 Posts

6 October 2009 at 3:33pm

You were close, just had to make it to SQL Query per the instructions in the link you posted


Forum Moderator, 5523 Posts

6 October 2009 at 4:51pm

And for $Top.Link/show/$ID you would just remove the / before the show - {$Top.Link}show/$ID


Community Member, 173 Posts

6 October 2009 at 10:00pm

Thanks Dalesaurus, thanks Willr,

i got it all working. If you read the docs carefully you can nearly solve every problem. To get all Data i had to build a foreach-loop.

Here is the code from my controller:

function getFirmenforBanner() {
$sqlQuery = new SQLQuery();
$sqlQuery->select = array(
'Firmenname AS Firmenname',
'Bereich AS Bereich',
'SiteTree.URLSegment AS URLSegment',
'SiteTree.Title AS Title',
'Stammdaten.ClassName AS ClassName',
'Stammdaten.ClassName AS RecordClassName',
'Stammdaten.ID AS ID'
$sqlQuery->from = array(
"LEFT JOIN SiteTree ON Stammdaten.Bereich = SiteTree.ID"
$sqlQuery->where = array(
"SiteTree.ShowInMenus = 1 AND Bereich = ".$this->ID.""
$result = $sqlQuery->execute();
$firmen = new DataObjectSet();
foreach($result as $row) {
$firmen->push(new ArrayData($row));

return $firmen;