Post Index ID
-
The templating system allows for some variables to be use when looping through posts in a topic.
For example, @first, @last
<!-- BEGIN posts --> <!-- IF @first --> <h1>Main Author: {posts.username}</h1> <!-- ENDIF @first --> {posts.content} <!-- IF @last --> End of posts. Click here to scroll to the top. <!-- ENDIF @last --> <!-- END posts -->
The BenchpressJS documentation says that @index @key and @value are available too.
Indeed when you print out @index it will show the index of the post DISPLAYED in the topic, with 0 being the first post displayed on the page.I'm trying to create a modification to my template so that some HTML is displayed after the second post. Therefore my logic would be:
<!-- IF @index == 1 --> Some HTML Goes here <!-- ENDIF @index == 1 -->
It seems that these kind of conditionals can't be used.
So what would be a way to get HTML to render after the Nth post in a topic page (with pagination enabled). -
@eesty mm... that's difficult to say. As you've discovered, you can do
{{{if @first}}}
and correspondingly{{{if !@first}}}
(also@last
), but more complicated logic is not possible.Why? Because elimination of more complex logic is what makes Benchpress so fast!
It looks like you'll want to use a helper to achieve this... but just in case there is a way, I'm going to ping @Pitaj.
-
Yeah so essentially what you want is to do is create an equals template helper, here are a couple resources from the past:
https://community.nodebb.org/topic/11406/how-can-i-print-out-a-specific-array-entry-in-my-template
https://community.nodebb.org/topic/3554/how-to-create-and-use-a-template-helper/9
And the benchpress docs
https://github.com/benchpressjs/benchpressjs/blob/master/docs/readme.md