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

Discussion in 'XenForo Development Discussions' started by hqarrse, Apr 11, 2014.

  1. hqarrse

    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?
  2. Chris D

    Chris D XenForo Developer Staff Member

    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.
    Daniel Hood, Steve F, AndyB and 3 others like this.
  3. hqarrse

    hqarrse Active Member

    Superb - thanks very much. I will have a stab!
  4. hqarrse

    hqarrse Active Member

    Up and running. Thanks very much Chris D for fast, concise guidance. That saved me a vast amount of time and pain.
    Chris D likes this.

Share This Page