XF 2.1 Looking for help with a simple addon

Hello! I've read through a ton of addon tutorials and find that I'm having trouble creating what should be fairly simple. I think I'm just missing one piece of understanding, so any help would be greatly appreciated.

I'm trying to create a simple addon that shows "X posts remaining" on the right side of the "1,2,3...Last" navigation bar at the bottom of a thread page (except on the last page).

Here's what I've done so far:
  1. Updated config.php to set debug mode to true and development enabled to true. Set defaultAddon as "RemainingPosts"
  2. php cmd.php xf-addon:create on my server with "RemainingPosts" as the ID for my addon.
  3. Modified addon.json to add my name, url, and a logo.
  4. Created a module in the addons folder: /addons/RemainingPosts/Template/TemplateFunctions.php:
    PHP:
    <?php
    
    namespace RemainingPosts;
    
    class RemainingPosts
    {
        public static function remainingPosts($total, $perPage, $page)
        {
            if ($total > $perPage)
            {
                $totalPages = ceil($total / $perPage);
    
                if ($page < $totalPages)
                {
                    $remaining = $total - ($page * $perPage);
                    $html = '<div class="postsRemaining">' . $remaining . ' More Posts...</div>';
    
                    return $html
                }
            }
    
            return '';
        }
    }
  5. Found the template that needs to be modified (thread_view) and where I want my function to go (inside <div class="block-outer block-outer--after">, after xf: pagenav and before xf:showignored). And formulated (but did not insert) what I think I want my line to look like:
    HTML:
    <???:remainingPosts
        page="{$page}" perPage="{$perPage}" total="{{ $thread.reply_count + 1 }}"
        wrapperclass="block-outer-opposite" />
This is where I'm stuck. I'm basically unsure how to:
  1. Make sure my remainingPosts method is actually accessible to this template (what should go in the ??? for example?)
  2. Modify the template in an "add-on" fashion rather than directly in the xenForo admin panel so that I can package my TemplateFunctions and the modification together.
Any help would be greatly appreciated. Thank you!
 
Hi all, I'm just looking for any help here. I'm sure it's a simple bridge to gap and I'm just missing something simple that would enable me to finish this, test it, put it on github, and write up an explanation for others to follow in my footsteps.

Any help would be greatly appreciated. Any response of any kind, at this point, would be appreciated tbh.
 
Two things:
1. It's highly unlikely you will be able to add custom template tags. There's too high a risk of significant breakage if you do that.
2. Your namespace / class name is wrong. A file in src/addons/RemainingPosts/Template/TemplateFunctions.php would have namespace RemainingPosts/Template; and class TemplateFunctions.

Outside of that, I would recommend looking into xf:callback instead of trying to add a new template tag.
 
Two things:
1. It's highly unlikely you will be able to add custom template tags. There's too high a risk of significant breakage if you do that.
2. Your namespace / class name is wrong. A file in src/addons/RemainingPosts/Template/TemplateFunctions.php would have namespace RemainingPosts/Template; and class TemplateFunctions.

Outside of that, I would recommend looking into xf:callback instead of trying to add a new template tag.

Thanks! Will look into xf:callback this evening and see if that makes more sense to me. I appreciate the response!
 
Top Bottom