- jmvaughn responded to »error when i try to upgrade to the last version of dizkus module (3.1)« 12:05 PM
- localrags responded to »Remove contents of nuke_sc_anticracker from Database« 11:30 AM
- jmvaughn created topic »TagIt 3.0 for Zikula« 09:34 AM
- jmvaughn responded to »Shoutit for zikula 1.3?« 09:31 AM
- mdee responded to »Different page content under one template (tpl file) based on URL« 07:17 AM
- espaan responded to »Categories disappear when editing ...« 08. Feb
- eledril responded to »How decrease zikula cpu usage« 08. Feb
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
Wiki » HooksInTemplates
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
