André Luiz André Luiz - 2 months ago 24
PHP Question

Phalcon PhP - how to disable the main layout for an action

I'm creating a action in one of my phalcon controller which will be used to generate a print version of a page. Here is my print.volt layout:

<!DOCTYPE html>
<html lang="en">
<!-- Begin page content -->
<div class="container">
{% block content %}{% endblock %}

And my view:

{% extends "layouts/print.volt" %}
{% block content %}
<script type="text/javascript">
{% endblock %}

It is working, but my problem is that the content generated is inserted inside another layout that has the
{{ content() }}
tag. At the end O get a page with all the website menus, my print.volt and my view. I would like to know how can I get just the view inserted inside the print.volt, without the master layout. How can I disable this behavior?

Thanks for any help!


Two options come to mind.

1) Use Simple view, which can render a template without the layout:

$view = new \Phalcon\Mvc\View\Simple();
$html = $view->render('template-name', $params);

This option is also really handy when generating HTML for email sending.

2) Disable the layout for the current Controller::method


3) Update: Timothy recommended an alternative to (2)