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

Return a Xenforo template

Zephyr

Well-known member
#1
Hi, i have a .php.
I would like returned a xenforo template and passing variables.

My code :

PHP:
    // Secret BBcode (Display a message if the user has a specific id)
    public static function parseSecret(array $tag, array $rendererStates, &$parentClass)
    {
        if (!empty($tag['option']) && $parentClass->parseMultipleOptions($tag['option']))
        {
            $attributes = $parentClass->parseMultipleOptions($tag['option']); // Id's
            $userSecretMessage = $tag['children'][0]; // Message
 
            foreach($attributes as $usersId)
            {
                $usersIdString = $usersId . ',';
            }
 
            return /* HERE LOAD A XENFORO TEMPLATE AND PASSING VARIABLES */;
            // Variables to pass: $usersIdString and $userSecretMessage
        }
    }
How can I do that please ? :)
 

Jake Bunce

XenForo moderator
Staff member
#2
Example code from one of my addons:

Code:
				$template = new XenForo_Template_Public('nat_childlinks', array(
					'firstChildNodes' => $firstChildNodes,
					'selected' => $selectedTabId == 'nodetab' . $nodeTab['node_id'],
					'nodeTypes' => $nodeModel->getAllNodeTypes()
				));
				$childLinks = $template->render();
The template name is nat_childlinks. And it passes an array of template params. Then it renders the template and stores it in $childLinks.