XF 2.0 How can I get JS/CSS calls in template rendered in code?

Jaxel

Well-known member
I am parsing bbCodes in one of my addons with the following:
Code:
$html = \XF::app()->bbCode()->render($this->content, 'html', 'content_type', $this,
    $this->getBbCodeRenderOptions($this, 'content_type'));

Is there any way to get a list of the JS/CSS (xf:js and xf:css) calls that were made in the bbCode templates?
 
Check out /src/XF/Template/Templater.php, it contains getIncludedCss() and getIncludedJs()
Wouldn't that require me to know what templates were being called though? If it's just parsed bbCode, I wouldn't know that.
 
I am parsing bbCodes in one of my addons with the following:
Code:
$html = \XF::app()->bbCode()->render($this->content, 'html', 'content_type', $this,
    $this->getBbCodeRenderOptions($this, 'content_type'));

Is there any way to get a list of the JS/CSS (xf:js and xf:css) calls that were made in the bbCode templates?

What if you add a code listener at templater_template_post_render and check the values of $templater->includeJs and $templater->includeCss. Of course you need to enable a switch before rendering the bbCode and disable it afterwards, so the listener will only check the relevant values, i.e. templates rendered during the time the switch is enabled. I haven't tried it myself, just an idea off the top of my head.
 
Wait, my bad. We are talking about bbCodes - what kind of templates? They are not tied to regular templates. There are templates like lightboxes etc, but these get called explicitly.
@PatM: You can tie a code event listener to a hint, so you actually don't need a switch.
 
The hint in this case would be the name of the template I guess but we don't know the names of the templates rendered, so we can't include any hints. I was talking about a switch such as $isBbCodeBeingRendered = true; and the listener will compose the list or just skip based on the value of this variable. Of course the variable needs to be passed to the listener somehow but that's not a big problem.
 
Back
Top Bottom