1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Addon Route / Breadcrumb / Page Help

Discussion in 'XenForo Development Discussions' started by lasertits, Nov 13, 2011.

  1. lasertits

    lasertits Active Member

    I'm trying to make my first addon that isn't just a simple templateHook/Create. Basically I'm just trying to put a tab in the main nav, that goes to my custom page / template, and can go to sub pages and the breadcrumb will keep the right structure.

    I've pulled off getting a tab in the nav with a drop down template, which goes to a index template, and the breadcrumb has "Home > Rules" (addon is for a bunch of rule pages), but I can't figure the best way to go about adding MORE pages, rather than JUST an index.

    Here's what I have so far:

    library/Rules/ControllerPublic/Index.php
    library/Rules/Listener/NavTabs.php
    library/Rules/Route/Prefix/Index.php

    library/Rules/ControllerPublic/Index.php:
    PHP:
    <?php
    class Rules_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
    {
        public function 
    actionIndex()
        {
            return 
    $this->responseView('Rules_ViewPublic_Index''Rules_Index');
        }
    }
    library/Rules/Listener/NavTabs.php:
    PHP:
    <?php
     
    class Rules_Listener_NavTabs
    {
        public static function 
    addNavbarTab(array &$extraTabs$selectedTabId)
        {
            
    $extraTabs['rules'] = array(
                
    'title' => new XenForo_Phrase('rules'),
                
    'href' => XenForo_Link::buildPublicLink('full:rules'),
                
    'position' => 'middle',
                
    'selected' => ($selectedTabId == 'rules'),
                
    'linksTemplate' => 'Rules_NavTabs',
            );
        }
    }
    library/Rules/Route/Prefix/Index.php:
    PHP:
    <?php
     
    class Rules_Route_Prefix_Index implements XenForo_Route_Interface
    {
        public function 
    match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            return 
    $router->getRouteMatch('Rules_ControllerPublic_Index''index''rules'$routePath);
        }
    }

    And the two templates I put together quickly for testing:

    Template Rules_NavTabs:
    Code:
    <ul class="secondaryContent blockLinksList">
        <li><a href="{xen:link rules/global}">Global Server Rules</a></li>
    </ul>
    
    Just has 1 example link for now.

    Template Rules_Index:
    Code:
    <xen:navigation>
        <xen:breadcrumb source="$nodeBreadCrumbs" />
    </xen:navigation>
     
    Index Content
    
    (not sure how to use the navigation/breadcrumb bits fully yet).

    So to reiterate, I'm trying to figure out the best way to go about adding more rules pages / sub pages. Breadcrumb structure is important, probably going to have a structure similar to this:

    Home > Rules (index / site and forum rules here)
    Home > Rules > Global Server Rules (rules for all our game servers)
    Home > Rules > CS:S (index listing sub pages perhaps)
    Home > Rules > CS:S > Mini Games
    Home > Rules > CS:S > Zombie Mod
    Home > Rules > TF2 (index listing sub pages perhaps)
    Home > Rules > TF2 > Payload 24/7
    Home > Rules > TF2 > Stock 24/7
    Home > Rules > Minecraft

    etc.

    I'd guess that each page would be its own template? E.g. Rules_SiteForum, Rules_GlobalServer, Rules_CSS, Rules_MiniGames, etc.

    But again, I'm really not sure / have no idea - hence this thread. Looking for any input / insight so I can hopefully be pointed in the right direction on how to pull this off properly. Thanks.
     
  2. lasertits

    lasertits Active Member

    Sorry for the bump. No one knows an easy / ideal way to add more pages to the addon? They're going to be static, so as I said I figured they can just be templates? Still looking for some wise words on this if anyone has any. I'm clearly new to this but I'm trying, just need a little kick in the right direction is all.

    If I had to guess I'd say I'd be doing something with the ControllerPublic, as that seems to define what template the index uses, but I really haven't a clue at this stage. Do I just use that same Index.php and define another response view / template?

    As always any help is greatly appreciated. I'll pay it forward, when I am able :)
    Thanks
     
  3. Bob

    Bob Well-Known Member

    Not sure why you don't just use pages to do this since its just a bunch of static content, but if I am understanding you correctly, you could always just add some actions to your ControllerPublic like this..

    PHP:
        public function actionMinecraft()
        {
            return 
    $this->responseView('Rules_ViewPublic_Minecraft''rules_minecraft_template_name');
        }
    When you type in domainname/rules/minecraft it would then display your 'rules_minecraft_template_name' page.
     
  4. lasertits

    lasertits Active Member

    Wanted to avoid pages as, to my knowledge, that would make the end result select the Forum tab, and the breadcrumb would reflect that as well. With an addon I can have the nav tab with its own sub menu, breadcrumb, etc. Just seemed to be the way to go in this case, if not, I'm definitely open to any alternative suggestions anyone might have.

    I figured something in the ControllerPublic would be the way to go, unfortunately I can't seem to get it going. Here's the modified ControllerPublic Index:

    PHP:
    <?php
    class Rules_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
    {
        public function 
    actionIndex()
        {
            return 
    $this->responseView('Rules_ViewPublic_Index''Rules_Index');
        }
        public function 
    actionMinecraft()
        {
            return 
    $this->responseView('Rules_ViewPublic_Minecraft''Rules_Minecraft');
        }
    }
    Then in Xen, I defined a master Rules_Minecraft template, however, upon going to site.com/rules/minecraft, it simply loads the Rules_Index template. It does this no matter what though, site.com/rules/asdjhaskjdhasd will also show index and so forth. Something must not be quite right in a snippet of code somewhere, that or I need to plug in a little more data / functionality than it has currently.

    Thanks for the reply, it's the type of response I was looking for, I just need to narrow this issue down some how though. Suggestions & ideas welcome, as your guess is probably better than mine at this point.
     
  5. Bob

    Bob Well-Known Member

    Change your route prefix to this and try it again.

    PHP:
    <?php
     
    class Rules_Route_Prefix_Index implements XenForo_Route_Interface
    {
        public function 
    match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            return 
    $router->getRouteMatch('Rules_ControllerPublic_Index'$routePath'rules');
        }
    }
     
  6. lasertits

    lasertits Active Member

    Nice! That did the trick. :D

    Now I just need to do some thinking on how I want to organize this then figure out my breadcrumbs / structure.

    Thanks for the help - greatly appreciated! Hopefully I don't run into any more snags. (y)
     

Share This Page