Oldest known version of this page was edited on 2009-08-17 12:06:41 by espaan [ Added a paragraph about permissions and enabling/disabling individual hooks ]

Hooks in Templates


If you ever wanted to use more than one display hook in your pnRender templates, you will stumble over the problem that all hooks are shown at the same place, one after the other.

The reason for this is simple:

<!--[ pnmodcallhooks hookobject=item hookaction=display hookid=$topic.topic_id ]-->


(The above code was taken from pnforum_user_viewtopic.html.)

This 'glues' all display hooks together in one piece.

Instead, use the following code, which assigns a new variable $hooks to the pnRender object.

<!--[ pnmodcallhooks hookobject=item hookaction=display hookid=$topic.topic_id implode=false ]-->


This variable $hooks is an array of the output from all the display hooks activated, which can now be positioned in your template where ever you want them to appear. For instance:

<div class='trackback'>
    <!--[ $hooks.trackback ]-->
</div>
.
. some more content
.
<div class='comments'>
    <!--[ $hooks.EZComments ]-->
</div>


This solution is simple but effective.

Enabling/disabling specific hooks and permissions


In the News module there is a specific flag for disabling commenting on a single article. Just like above, when you call the hooks plugin without any specific parameters, all hooks are used. The following construction makes it possible to disable one hook by using your specific module/template needs:

<!--[pnmodurl modname='News' func='display' sid=$info.sid assign='returnurl']-->
<!--[pnmodcallhooks hookobject='item' hookaction='display' hookid=$info.sid module='News' returnurl=$returnurl owneruid=$info.cr_uid implode=false]-->
<!--[foreach from=$hooks key='hookname' item='hook']-->
<!--[if $hookname neq 'EZComments' or $info.withcomm eq 0]-->
<!--[$hook]-->
<!--[/if]-->
<!--[/foreach]-->


Also note that there is a parameter owneruid in the pnmodcallhooks plugin call. This makes sure that, for instance with EZComments, the correct permissions are being used. In this case the author (cr_uid) of the news article is the owner, so hooks can use that to enable edit/delete possibility for instance.
Only if the hook is Not EZComments or the variable $info.withcomm equals 0 the hook is called. Which means that by setting the flag withcomm to 1 the EZComments hook is not called in this case.


CategoryDeveloperDocs