3212 Posts in 847 Topics by 809 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1520 Views |
-
Referencing Page control variables from within a dataobject?

2 September 2010 at 4:41pm Last edited: 8 September 2010 6:19am
I'm trying to build a 2-level nav where the 2nd level link is comprised of the URL from the 1st level and an anchor identifier placed by a dataobject.
In short,<% control Menu(1) %>
<ul class="$URLSegment $LinkOrSection">
<li><a href="$Link" class="$Title" title="$Title">$Title<!--[if IE 7]><!--></a><!--<![endif]-->
<div class="link_sub">
<ul class="sub">
<% if Meals %>
<% control Meals %>
<% control ItemCategories %>
<li><a href="$Link#$Name" title="$Name">$Name</a></li>
<% end_control %>
<% end_control %>
I can pull $Name from ItemCategories, but can't find a way to grab $Link from the Menu(1) controller. Do I need to write a custom method just to pull $Link from the page related to the dataobject? -
Re: Referencing Page control variables from within a dataobject?

8 September 2010 at 6:19am
Changed the topic to one that I think might make more sense.
-
Re: Referencing Page control variables from within a dataobject?

8 September 2010 at 8:08am
Try $Top.Link
-
Re: Referencing Page control variables from within a dataobject?

10 September 2010 at 2:46am
Unfortunately, this just gives every 2nd level link a reference to the current page, not the parent page in the menu.
<% control Menu(1) %>
<% if LinkOrSection="link" %>
<ul class="$URLSegment $LinkOrSection">
<li><a href="$Link" class="$Title" title="$Title">$Title<!--[if IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<div class="link_sub">
<ul class="sub">
<% if Meals %>
<% control Meals %>
<% control ItemCategories %>
<li><a href="$Top.Link" title="$Name">$Name</a></li>
<% end_control %>
<% end_control %> -
Re: Referencing Page control variables from within a dataobject?

17 September 2010 at 2:51pm
I think I'm getting closer. They key, near as I can see it, is to write a function for the ItemCategory class that will find the ID of the parent DataObject Meal (Menu), then find the parent Page (Menu), then - from that - get the URLSegment. This is as far as I've gotten:
function MenuItemLink(){
$MealsID = $this->MealsID;
$Menu = DataObject::get('Menu', "MealsID = '{$MealsID}'");
}
But $Menu is returned as a DataObjectSet. Shouldn't it just be 1 DataObject? -
Re: Referencing Page control variables from within a dataobject?

17 September 2010 at 3:40pm
DataObject::get will always return a DataObjectSet even if there's just one DO in it.
Given your code you could use DataObject::get_by_id("Menu", $MealsID) or DataObject::get_one() if you wanted to add more to the query.
hth
| 1520 Views | ||
|
Page:
1
|
Go to Top |

