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

Page creation during add-on install

Discussion in 'XenForo Development Discussions' started by LPH, May 18, 2014.

  1. LPH

    LPH Well-Known Member

    I'm finally pushing forward on a free add-on for the community. It's kicking my butt because my knowledge of MVC and the XenForo way is different from the WordPress spaghetti ;)

    I'm really trying to wrap my head around things.

    First, using templateHooks is deprecated since XF 1.2, correct? So code like this is "out-dated"

    PHP:
    class XenAddOn_Listener_core
    {
    public static function 
    templateCreate(&$templateName, array &$paramsXenForo_Template_Abstract $template)
    {
    if(
    $templateName == 'PAGE_CONTAINER')
    {
    $template->preloadTemplate('xenaddon_main');
    }
    }
    public static function 
    templateHook($hookName, &$contents, array $hookParamsXenForo_Template_Abstract $template)
    {
    switch (
    $hookName)
    {
    case 
    'footer_links':
    {
    $contents .= '<li><a href="/community/link_to_addon_page">An Add-on</a></li>';
    break;
    }
    case 
    'navigationTabs':
    {
    $contents .= $template->create('xenaddon_main');
    break;
    }
    }
    }
    }
    If template hooks are deprecated then how does the add-on hook into XenForo so a new page is created? Yes, the above code does a link in the footer because I am following Kier's video on template hooks. But now I'm trying to find where tutorials are for adding a page via an add-on (not via the ACP).

    Any guidance would be appreciated.
     
  2. Valhalla

    Valhalla Well-Known Member

    You should use the Template Modification system in place of template hooks.

    I think that, typically, new pages are created by the means of creating a new "Route Prefix", then by assigning the desired template which should be called from your ControllerPublic file.

    When you have this set up, however, you shouldn't need to include reference to PAGE_CONTAINER, just your custom content, because the previously mentioned template is just that - the container.
     
    Last edited: May 18, 2014
  3. LPH

    LPH Well-Known Member

    @Valhalla - Thank you!

    I was just getting ready to update this post because I've been reviewing XenForo Resource Manager code. Unfortunately, my route prefix isn't working ...

    These are my current files:

    /XenTicket
    — /ControllerPublic/Ticket.php
    — /Listener/Template.php
    — /Route/Prefix/Tickets.php

    The Tickets.php is a duplicate of the one from XF resources pointing to /resources -- but there are some subcomponents that haven't been built and that may be why it is failing.

    Thank you for the clear explanation!
     
  4. Valhalla

    Valhalla Well-Known Member

    The Route Prefix should look like this:

    Screen Shot 2014-05-18 at 05.13.54.png

    The Route/Prefix/Tickets.php file would be something like:
    PHP:
    class XenTicket_Route_Prefix_Tickets implements XenForo_Route_Interface
    {
        public function 
    match($routePathZend_Controller_Request_Http $requestXenForo_Router $router)
        {
            return 
    $router->getRouteMatch('XenTickets_ControllerPublic_Ticket'$routePath'forums');
        }
    Your ControllerPublic/Ticket.php file would then load the template.
    PHP:
    class XenTicket_ControllerPublic_Ticket extends XenForo_ControllerPublic_Abstract
    {
        public function 
    actionIndex()
        {
            return 
    $this->responseView('XenTickets_ViewPublic_XenTickets''my_template');
        }
    You might choose to alter your file names and classes to be more consistent (i.e. dropping plurals).
     
    Last edited: May 18, 2014
  5. LPH

    LPH Well-Known Member

    Slaps head !

    I didn't have the route prefix in the ACP entered.

    Removed $viewParams for now. Loads the template just fine :)

    Thank you @Valhalla
     
  6. LPH

    LPH Well-Known Member

    Decided to continue on same thread ....

    Goal is to show the latest threads on this newly created page. It's kicking my butt.

    The page loads fine (since adding the route prefix). I can make changes in the template and they are reflected on the newly created page.

    Attempted to simply use a foreach loop to list the latest threads in the template being called by the ControllerPublic. The viewParams are set for $thread_id (I think).

    Here is the general layout of the loop.

    Code:
    <xen:foreach loop="$thread_id" value="???">
         // latest threads
    </xen:foreach>
    
    I'm missing a step somewhere because I'm getting an invalid argument. What belongs in the value ?
     
  7. Brogan

    Brogan XenForo Moderator Staff Member

    Typically it would be something like this: <xen:foreach loop="$threadIds" value="$threadId">
     
  8. LPH

    LPH Well-Known Member

  9. Jeremy

    Jeremy XenForo Moderator Staff Member

  10. LPH

    LPH Well-Known Member

  11. LPH

    LPH Well-Known Member

    I might actually be getting this working. I'm now putting the model together.

    @AndyB -> ShowDeleted add-on has been a tremendous help. Between his posts and code, as well as everyone else helping, I'm starting to understand how XF is built. I think :whistle:
     

Share This Page