XF 2.2 Output HTML without PAGE_CONTAINER

stromb0li

Active member
Is it possible to output HTML from a template/view without rendering the PAGE_CONTAINER template? I noticed I can echo out HTML followed by exit() to halt processing of everything else to only show what I want, but this feels horribly wrong/messy.
 
In your template:

HTML:
<xf:page option="template"></xf:page>

You can also create your own container template and pass that instead, depending on your exact needs.
 
Sorry to bump up an old topic, but similarly, in my controller if I want to surface a file download, what is the proper way to render that vs a view? I feel like using exit() is really bad practice ha
 
You can accomplish this with a view class:

Controller action:
PHP:
$this->setResponseType('raw');

// ...

$viewParams = [
    'file' => 'your file contents',
    // ...
];
return $this->view('Some\AddOn:Some\Page', '', $viewParams);

View class:
PHP:
<?php

namespace Some\Addon\Pub\View\Some;

use XF\Mvc\View;

class Page extends View
{
    public function renderRaw()
    {
        // you can pass view params for deriving these dynamically if applicable
        $this->response->contentType('some/mime', '');
        $this->response->setDownloadFileName('your-file.ext');

        return $this->params['file'];
    }
}
 
Top Bottom