phpBB

Development Wiki

Difference between revisions of "Add Template Listeners"

From phpBB Development Wiki

(How to use one)
(Adding ACP template listeners: Now the ACP template listeners should be located in ext/<vendor>/<ext_name>/adm/style/event/)
Line 18: Line 18:
  
 
If you want to add ACP template listener, place corresponding html file in
 
If you want to add ACP template listener, place corresponding html file in
<pre>ext/&lt;vendor&gt;/&lt;extname&gt;/styles/&lt;adm&gt;/template/event/</pre>
+
<pre>ext/&lt;vendor&gt;/&lt;extname&gt;/adm/style/event/</pre>
  
 
For example, if you want to add template listener for acp_forums_normal_settings_append event located in adm/style/acp_forums.html, you need to create a file:
 
For example, if you want to add template listener for acp_forums_normal_settings_append event located in adm/style/acp_forums.html, you need to create a file:
<pre>ext/&lt;vendor&gt;/&lt;extname&gt;/styles/adm/template/event/acp_forums_normal_settings_append.html</pre>
+
<pre>ext/&lt;vendor&gt;/&lt;extname&gt;/adm/style/event/acp_forums_normal_settings_append.html</pre>
  
 
==Template Cache==
 
==Template Cache==

Revision as of 22:34, 27 May 2014

What are template listeners?

Template listeners are a way of injecting code into the template files. The can be injected at any place where events are used. They are part of the listeners system added in 3.1

How to use one

I'm assuming you already know what the events's identifer is. If you don't then you should look it up on the Events_List. If it isn't on the events list you can add it as described in the Adding_Events article.

So lets say our event is called overall_header_head and injects into overall_header.html in the head element.

You create a file in your extension in
ext/<vendor>/<extname>/styles/<stylename>/template/event/overall_header_head.html

You essentially call the file by the event identifier and place it in the event/ subdirectory of the style's template folder.

Then you type in the content you want to be injected where that event is and you're good to do. It's as simple as that.

If you want it to work for all styles (recommended) then instead of style name use `all`.

Adding ACP template listeners

If you want to add ACP template listener, place corresponding html file in

ext/<vendor>/<extname>/adm/style/event/

For example, if you want to add template listener for acp_forums_normal_settings_append event located in adm/style/acp_forums.html, you need to create a file:

ext/<vendor>/<extname>/adm/style/event/acp_forums_normal_settings_append.html

Template Cache

When parsing and caching the template file, phpBB by default checks for all available listeners at compile time and includes them in the compiled template. This makes rendering the page faster after it is compiled.

The default behavior makes it more difficult to develop extensions because when adding or removing template event files, the cache must be purged. To prevent having to purge the cache all the time, you can enable DEBUG_MODE in your config.php file, which will force the template engine to ALWAYS look for template event files when the page is being rendered.