XF 2.1 How to get template name from Custom BB code callback?

Slion

Active member
Can I somehow access the template name from the templater object?
Basically I would like to understand if the thread preview is being rendered.
 
It is tracked in the templater object, though it's not exposed externally. You'd have to extend the templater if you wanted to do that.

Strictly speaking, the ideal way to change the behavior of rendering is based on the context we setup the BB code renderer with. For example, thread_preview renders with "post:thread_preview" as the context. This is passed into XF\Entity\Post::getBbCodeRenderOptions() to setup the options/data for the BB code renderer.

So you could check the context there and adjust the options you pass to the BB code renderer (and then have your callback change behavior based on some sort of flag).

The context is also passed into the BB code rule set, so I think you can also access the getRules() method on the renderer object (which then exposes getContext and getSubContext).
 
It is tracked in the templater object, though it's not exposed externally. You'd have to extend the templater if you wanted to do that.
Thought of that yesterday and tried it as you were writing your answer but for some reason it won't instantiate my class. It keeps on instantiating the one from XF. So no joy there.

The context is also passed into the BB code rule set, so I think you can also access the getRules() method on the renderer object (which then exposes getContext and getSubContext).
That works great thanks. Just what I was looking for. Are the different contexts and sub-contexts documented somewhere?
 
Are the different contexts and sub-contexts documented somewhere?
Not exactly, as it's intentionally free form to handle any situation that comes up.

But it does follow a pattern. The sub-context is optional and the main context is a content type. So for example, viewing a post in a thread is the "main" context for that, so it's just post (no sub-context). You'll see things like profile_post, conversation_messsage, etc.

Special cases are where we would tend to use a sub-context. So post:thread_preview in the example case (or post:preview for when someone presses the preview button a message).
 
Back
Top Bottom