Slion
Active member
I'm trying to implement some BB code add-on that would build a Table Of Content for a post.
I'm new to PHP and XenForo and have never implemented add-ons before.
However I'm familiar with Perl and other web applications.
I would like to publish the following BB codes: H1 to H6 and TOC.
I got my Hx BB code working.
Now I would like to be able to store information between callbacks call so that this information is available to each of my callbacks.
The idea would be for Hx BB code to record themselves in some kind of data structure that the TOC callback could use to render itself.
If I can get the TOC to render last that should just work, right?
So far I tried using load class bb code data member and rendererStates but neither worked.
They are not preserved between callback calls.
@Chris D Since you are online now, maybe you could help me out there?
I'm new to PHP and XenForo and have never implemented add-ons before.
However I'm familiar with Perl and other web applications.
I would like to publish the following BB codes: H1 to H6 and TOC.
I got my Hx BB code working.
Now I would like to be able to store information between callbacks call so that this information is available to each of my callbacks.
The idea would be for Hx BB code to record themselves in some kind of data structure that the TOC callback could use to render itself.
If I can get the TOC to render last that should just work, right?
So far I tried using load class bb code data member and rendererStates but neither worked.
They are not preserved between callback calls.
PHP:
<?php
/**
*/
class Slions_Toc_BbCode_Formatter_Base extends XFCP_Slions_Toc_BbCode_Formatter_Base
{
//protected $_tags;
protected $rendersCount;
/**
* Override getTags to publish our ouwn BB codes.
*/
public function getTags()
{
$tags = parent::getTags();
$tags['h2'] = array(
'hasOption' => false,
//'replace' => array('<h2>', '</h2>')
'callback' => array($this, 'renderTagHeader')
);
return $tags;
}
/**
* @param array $tag Information about the tag reference; keys: tag, option, children
* @param array $rendererStates Renderer states to push down
*
* @return string Rendered tag
*/
public function renderTagHeader(array $tag, array $rendererStates)
{
if (!isset($rendererStates['slionsHeaderCount']))
{
$rendererStates['slionsHeaderCount'] = 0;
}
$output = '<h2>' . $rendererStates['slionsHeaderCount'] . $tag['children'][0] . '</h2>';
$rendererStates['slionsHeaderCount']++;
return $output;
}
}
@Chris D Since you are online now, maybe you could help me out there?
Last edited: