1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Template Hooks

Discussion in 'XenForo Development Discussions' started by Daniel Hood, Nov 5, 2013.

  1. Daniel Hood

    Daniel Hood Well-Known Member

    Since template hooks are depreciated, how are you guys going about using the existing ones? Do you just use them as you did before, do you use a template mod regex find/replace to add your content inside the hooks, or do you avoid the hooks entirely and use template modifications to append to something else?
  2. Chris D

    Chris D XenForo Developer Staff Member

    I try to avoid template hooks completely now.

    That being said, the advertising system for AVForums relies heavily on them. But I have a plan in case they're ever completely removed from the core. The concept was devised actually before they were deprecated.

    But when developing anything, that is what is in the back of my mind. What if 1.3 comes along and that template hook isn't there anymore? Or worse, the entire code event is removed?

    So best bet is to completely avoid them.
  3. Jeremy

    Jeremy XenForo Moderator Staff Member

    You should be using template modifications and migrating any pre-existing addons to the template modifications. Hooks can be removed at any time.
  4. Daniel Hood

    Daniel Hood Well-Known Member

    Alright, I figured it would be best to avoid template hooks. Just looking for the best alternative.

    What replacement method would you use for this, for example? To add something after the trophy points line.

    <dl class="userStats pairsInline">
             <xen:hook name="member_card_stats">
                 <dt>{xen:phrase member_since}:</dt> <dd>{xen:date $user.register_date}</dd>             <!-- slot: pre_messages -->
                 <dt>{xen:phrase messages}:</dt> <dd><a href="{xen:link search/member, '', 'user_id={$user.user_id}'}" class="concealed" rel="nofollow">{xen:number $user.message_count}</a></dd>             <!-- slot: pre_likes --> 
                <dt>{xen:phrase likes_received}:</dt> <dd>{xen:number $user.like_count}</dd>             <!-- slot: pre_trophies -->
                 <dt>{xen:phrase trophy_points}:</dt> <dd><a href="{xen:link members/trophies, $user}" class="concealed OverlayTrigger">{xen:number $user.trophy_points}</a></dd>             <xen:if is="{$canViewWarnings}">
                     <dt>{xen:phrase warning_points}:</dt> <dd><a href="{xen:link members, $user}#warnings" class="concealed">{xen:number $user.warning_points}</a></dd>             </xen:if>
  5. Chris D

    Chris D XenForo Developer Staff Member

    Simple replacement:

    $0 Your extra content
    Daniel Hood likes this.
  6. Chris D

    Chris D XenForo Developer Staff Member

    Before now I've written ridiculously complicated regular expressions to do replacements such as the above. But actually, a lot of the time simple string replacements - as long as you're smart and don't do things like search/replace entire templates or across multiple lines. Although that will work, the more you match as a simple string I guess the more likely you are going to have problems come upgrade time.
  7. Daniel Hood

    Daniel Hood Well-Known Member

    Thanks for the tips Chris. Appreciate it.

Share This Page