• I'd like to target a specific post in the topic.tpl or partials/topic/post.tpl template.

    I can get the first post with !post.index

    How can I show a banner or insert some html below the 2nd post in any thread?


  • You can use helpers to make more complicated conditionals. For example:

    In your plugin (or theme's library.js):

    helpers.appendAdIfSecondPost = function(post) {
    	return parseInt(post.index, 10) === 2 ? '<strong>Here be an ad</strong>' : '';
    };
    

    In your template:
    {function.appendAdIfSecondPost}

    Here's an old thread explaining how to add helpers to your plugin: https://community.nodebb.org/topic/3554/how-to-create-and-use-a-template-helper


  • Thank you! Just what I needed to add some more functionality. Will study this a little bit more.. could open up some interesting possibilities.


  • šŸ™‚ the idea of the templating engine is to keep really complex stuff away from the HTML markup. Otherwise you can have really complicated looking HTML, while it really should just be a JS script.


  • Agree, just have to get used to the differences between what you have in NodeBB and PHP temptate engines like Smarty and vBulletin's built in engine.


Suggested Topics

| | |

Ā© 2014 ā€“ 2022 NodeBB, Inc. ā€” Made in Canada.