Fetching value of the latest page of a forum post for email template

Sam Mueller asked on March 9, 2017 15:33

I'm trying to retrieve the value of the last page where a forum post was posted for a New Post subscription email template.

Right now my "click to view forum" only brings the user to the beginning of the thread they subscribed to. I would like them to click on the link and bring them to the latest post in that thread but my "&tpage=" is missing the pager value.

Here's an example:

<a href="{%link%}&tpage={% #**Something should go here to get the latest page in thread**#%}">Click here to view forum</a>

Any help would be appreciated, thanks.

Correct Answer

Trevor Fayas answered on March 9, 2017 18:45

Okay, so this may be a little convoluted and you MAY want to consider a custom macro so you can use back end API but you need to:

  1. Get the DocumentID from the Link Path
  2. Get the ForumID using the DocumentID = Forums.Forum.ForumDocumentID
  3. Get the "ForumPosts" from that Forum object (total # of posts i belive)
  4. Divide that by the # of posts per page and round up (say 80 posts, 25 posts per page, 80/25 = 3.2 -> Round up to Page 4)

Additionally, in the Pager i would set the "Page Size" in a url parameter so your link will still work even if the default page size changes (put in the page size in your link).

I don't think you'll be able to easily complete this with the normal macro engine that is in Kentico since i don't think the Forum object is accessible directly. I would create a custom macro method that does what you are looking for.

Do you need help with that? Here's how to do it.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Sam Mueller answered on March 9, 2017 19:07

This line got me thinking:

"4. Divide that by the # of posts per page and round up (say 80 posts, 25 posts per page, 80/25 = 3.2 -> Round up to Page 4)"

I did something similar by using the PostThreadPostsAbsolute to get the post value of the current thread and dividing that with the number of posts displayed per page (in my case, it's 10) wrapped in a Math.Ceiling for the round up.

Thanks Trevor for suggesting this. Got me thinking about it in a different way.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.