Page creation during add-on install

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 &$params, XenForo_Template_Abstract $template)
{
if($templateName == 'PAGE_CONTAINER')
{
$template->preloadTemplate('xenaddon_main');
}
}
public static function templateHook($hookName, &$contents, array $hookParams, XenForo_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.
 
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:
@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!
 
The Route Prefix should look like this:

Screen Shot 2014-05-18 at 05.13.54.webp

The Route/Prefix/Tickets.php file would be something like:
PHP:
class XenTicket_Route_Prefix_Tickets implements XenForo_Route_Interface
{
    public function match($routePath, Zend_Controller_Request_Http $request, XenForo_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:
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
 
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 ?
 
Typically it would be something like this: <xen:foreach loop="$threadIds" value="$threadId">
 
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:
 
Back
Top Bottom