Problem with topctrl button in PAGE_CONTINER

Nerbert

Active member
I'm working on a project in which I want to put a file upload button in the topctrl position on the PAGE_CONTAINER template. I have the button in place but it's missing many of the data-xxxx attributes, in particular, those supplied by XenForo_Model_Attachment->getAttachmentConstraints(). These values are available to my main template but apparently not to PAGE_CONTAINER.

The button is based on the "Upload a File" button in the reply form. I'm using the template_create event and the following code

Code:
    public static function template_create(&$templateName, array &$params, XenForo_Template_Abstract $template)
    {
        if($templateName == 'PAGE_CONTAINER')
        {
        
            $template->preloadTemplate('attachment_handler_upload');

            $uploadButton = $template->create('attachment_handler_upload', $template->getParams());
        
            $params['topctrl'] = $uploadButton->render();
        }
    }

attachment_handler_upload is my template for the button based on attachment_upload_button template.

How do I make these param values available to PAGE_CONTAINER
 
How do I make these param values available to PAGE_CONTAINER
In general, you can't -- or at least it's not the route I would take.

Is there any reason you can't put your functionality in the specific template that needs it, which would presumably have the values you require? Using template-related events isn't the ideal way of customizing a template now (though it has its place); template modifications are generally better.
 
The problem is that the topctrl button would have to go into the PAGE_CONTAINER template, which I don't want to modify. I found the solution though

Code:
<xen:topctrl><xen:include template="attachment_handler_upload" /></xen:topctrl>

I had seen an article on doing this but I assumed you would have to put it in the template holding the topctrl position, but I tried it in my main body template and it worked just fine. I suppose things like that are evaluated before the HTML is rendered.

Anyway all the params come through and I have it working now.
 
Top Bottom