0
votes

I have following problem: Some links that show up in the Menu (the children of "Portfolio") are links to custom controllers. Of course now the LinkingMode is not available for that Links. Thats a image of the Menu:

enter image description here

So the children of Portfolio (Website, Application, etc.) are actually Category-DataObjects, which do not have a SiteTree Representation. The Submenu of Portfolio is created via checking and looping for all found categories in the Database.

The menu creation looks like that:

<ul>
    <% loop Menu(1) %>
    <li class="$LinkingMode">
        <a href="$Link">[$LinkingMode] $MenuTitle.XML</a>             
        <% if Children %>
        <ul class="secondary">         
            <% if ClassName == 'ProjectsPage' %>
                <% loop $Top.Categories %> <!-- loop all found categories, every found item links to the custom category controller -->
                    <li class="$LinkingMode"><a href="category/show/$Slug">$Name</a></li>
                <% end_loop %>
            <% else %>    
                <% loop Children %>
                    <li class="$LinkingMode"><a href="$Link"><span class="text">$MenuTitle.XML</span></a></li>
                <% end_loop %> 
            <% end_if %>
        </ul>
        <% end_if %>                
    </li>
    <% end_loop %>
</ul>

Every Category (Website, Mobile) in the Menu links to a custom controller, which looks basically like that:

class Category_Controller extends Page_Controller {
    public function show($arguments) {
        return $this; //there will be more code to display all projects of a category
    }
}

I expect that I have to add some custom code for the Category_Controller which tells the Portfolio Page which linkingmode it has...

Many thx, Florian

1
so you have class Category extends DataObject? and how do you identify the Category? by ID? as in mysite.com/category/show/1?Zauberfisch
ja exactly: class Category extends DataObject, each Category has a slug/id, which I use for identification. so the url looks like this: mysite.com/category/show/mobilespierala

1 Answers

2
votes

I´ve found good tips here:

http://www.ssbits.com/snippets/2009/extending-linkingmode-to-handle-controller-actions/

http://www.ssbits.com/tutorials/2010/dataobjects-as-pages-part-1-keeping-it-simple/

Thats the Category_Controller.php (a public var CategoryID is set there):

class Category_Controller extends Page_Controller {
public $CategoryID;

public function index($arguments) {
    $slug = $arguments->param("Slug");
    $category = Category::get()->filter(array('Slug' => $slug))->First();
    $this->CategoryID = $category->ID;
}
}

DataObject Category (LinkingMode function checks if the current CategoryID set in the Controller equals the ID of the Category DateObject):

class Category extends DataObject {  
    public function LinkingMode(){
        $categoryID = Controller::curr()->CategoryID;
        return ($categoryID == $this->ID) ? 'current' : 'link';
}
}

In the template you can check then the linking mode as usual:

<% loop $Categories %>
    <li class="$LinkingMode">$Name</li>
<% end_loop %>

Cheers, Florian