• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Theme Conditional - Target Xth Post

Scheduled Pinned Locked Moved Technical Support
themeconditional
5 Posts 2 Posters 3.2k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shri
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
  • psychobunnyP Offline
    psychobunnyP Offline
    psychobunny
    wrote on last edited by
    #2

    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

    1 Reply Last reply
    0
  • S Offline
    S Offline
    shri
    wrote on last edited by
    #3

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

    1 Reply Last reply
    0
  • psychobunnyP Offline
    psychobunnyP Offline
    psychobunny
    wrote on last edited by
    #4

    🙂 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.

    1 Reply Last reply
    0
  • S Offline
    S Offline
    shri
    wrote on last edited by
    #5

    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.

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development