How to know if there are attachments in a page

hqarrse

Active member
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?
 
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.
 
Up and running. Thanks very much Chris D for fast, concise guidance. That saved me a vast amount of time and pain.
 
Back
Top Bottom