Jaxel
Well-known member
This guide will explain how to make custom pages for your mods. The first thing you need to do is create your mod with a unique addon ID, and then create a directory in the /library/ folder to follow that ID. The name of your addon ID should begin with a letter; I tried to begin with a number, but it created programs as PHP doesn't like classes that start with numbers. For this example, I am using an addon ID I created called "World"... this will be a Hello World mod!
Once your mod is created, you will need to create a routing class. Based on the name of my mod, I created the class "World_Route_Prefix_Portal" at "/library/World/Route/Prefix/Portal.php".
This one is simple, the class contains a function that matches the URL a user inputs and sends it to the appropriate location. This function assumes the user will be going to the /portal/ URL and it will forward the user to /portal/index. For getRouteMatch, we are passing 4 parameters:
This function creates the second row of links for when you click on the Hello World primary tab. The primary tab is generated in a Template called "World_Navtabs"... which must be created.
In order to continue, we need to use XenForo's hook system called "Code Listeners". You can create new Code Listeners at the "admin.php?code-event-listeners/" link on your XF installation.
This one is simple, declare the action function for when someone goes to /world/index, store Hello World into a string, add the string to passable parameters, then call up the XenForo template generator called responseView. You'll notice a class called "World_ViewPublic_Index", thankfully you dont actually have to make this class, as it will be generated automatically. The second parameter however "World_Index" is referencing a template which must be created.
Not so simple is it eh? I made this guide off the top of my head, so if anything is wrong, please tell me.
Remember! I'm an unemployed programmer who enjoys donations!
Once your mod is created, you will need to create a routing class. Based on the name of my mod, I created the class "World_Route_Prefix_Portal" at "/library/World/Route/Prefix/Portal.php".
Code:
<?php
class World_Route_Prefix_Index implements XenForo_Route_Interface
{
public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
{
return $router->getRouteMatch('World_ControllerPublic_Index', 'index', 'world', $routePath);
}
}
- World_ControllerPublic_Index - this is the function we will be sending the user to
- index - you could put $routePath here, in order to have nested actionFunctions depending on if a user puts in /world/subdir or something along those lines. In this case, I am making it so that no matter what a user inputs, they will always be sent to /world/index.
- portal - this is a variable defining what 'navigation tab' the user is on. Just like the index field, you can customize this, but then you will need to make a navigation tab for each and every portal page. This is what is called the "Major Section"
- $routePath - this is what is called the "Minor Section". This field will store additional URL information beyond the /world/. So if a user goes to /world/edit, this field will contain "edit". You could use this information to redirect the user depending on whats in the Minor Section.
- Route Prefix: world
- Route Type: public
- Route Class: World_Route_Prefix_Index
Code:
<?php
class World_Listeners_Navigation
{
public static function navtabs(array &$extraTabs, $selectedTabId)
{
$extraTabs['world'] = array(
'title' => 'Hello World',
'href' => 'world/',
'selected' => ($selectedTabId == 'world'),
'linksTemplate' => 'World_Navtabs',
);
}
}
This function creates the second row of links for when you click on the Hello World primary tab. The primary tab is generated in a Template called "World_Navtabs"... which must be created.
Code:
<ul class="secondaryContent blockLinksList">
<li><a href="{$xenOptions.boardUrl}/world/">Hello World</a></li>
</ul>
In order to continue, we need to use XenForo's hook system called "Code Listeners". You can create new Code Listeners at the "admin.php?code-event-listeners/" link on your XF installation.
- Listen to Event: navigation_tabs
- Execute Callback: World_Listeners_Navigation::navtabs
Code:
<?php
class World_ControllerPublic_Index extends XenForo_ControllerPublic_Abstract
{
public function actionIndex()
{
$text = 'Hello World!';
$viewParams = array(
'text' => $text,
);
return $this->responseView('World_ViewPublic_Index', 'World_Index', $viewParams);
}
}
Code:
<xen:if hascontent="true">
<div class="sectionMain">
<xen:contentcheck>
{xen:raw $text}
</xen:contentcheck>
</div>
</xen:if>
Not so simple is it eh? I made this guide off the top of my head, so if anything is wrong, please tell me.
Remember! I'm an unemployed programmer who enjoys donations!