• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How to know if there are attachments in a page

hqarrse

Active member
#1
I want to set a template variable in the page_container_js_head template which will be true if there are any attachments in any posts on the current page (thread_view). The page_container_js_head template needs to know this before the full page is rendered as elements of the page are affected by the outcome.

Could someone give me a steer on where to work this out - ie. what code event listener to use?
 

Chris D

XenForo developer
Staff member
#2
The way I would do this:
  • Code event listener for load_class_controller
  • Extend XenForo_ControllerPublic_Thread::_postDispatch()
  • Check if the posts param exists in the controller response. Loop through those posts and add up the value of the attach_count
  • If the attach_count is > 0, set the a new param in containerParams called 'hasAttachments' or similar.
  • {$hasAttachments} will now be available in the page_container_js_head template.