Skip to content

Configuration

This page covers the configuration options available for this plugin, allowing you to customize template rendering behavior for your application needs.

Options

Set options via ViewBuilder::setOption() or setOptions():

OptionTypeDefaultDescription
cachebooltrueEnable/disable template caching. Caching is always enabled except when explicitly set to false.
autoRefreshboolfalse (or true in debug)Automatically refresh templates. Auto-refresh is always enabled in debug mode.
fragmentsarray,string'content'Fragment (block) name(s) that should be rendered when autoLayout is disabled. Read more
cachePathstringCACHE . 'latte_view'Path for compiled template cache
sandboxboolfalseEnable sandbox mode for secure template execution. When enabled, the security policy can be configured using setSandboxPolicy() and getSandboxPolicy().
rawphpbooltrueEnable/disable the use of raw PHP code in templates via the {php} tag.
defaultHelpersarray...List of default Cake helpers that need to be present. Defaults to all core helpers.

The fragments option.

The blocks option controls which template fragments (Latte blocks) are rendered when autoLayout is disabled. This feature enables you to return specific portions of a template without the full layout structure, making it ideal for partial page updates and AJAX responses.

Imagine you have this template

latte
<table>
    {block tableRows}
        {foreach $rows as $row}
        <tr>
            <td>Block 1 content</td>
        </tr>
        {/foreach}
    {/block}
</table>

{block content}
    {* other template content that we don't want in our response *}
{/block}

{block otherFragment}
    Block 3 content
{/block}

When configuring the ViewBuilder to return only specific blocks, you can generate focused template fragments for partial page updates or AJAX responses:

php
// Disable autoLayout first
$this->viewBuilder()->disableAutoLayout();

// Return only table rows for dynamic content updates
$this->viewBuilder()->setConfig('fragments', ['tableRows']);

// Return multiple fragments for complex partial updates
$this->viewBuilder()->setConfig('fragments', ['tableRows', 'otherFragment']);

This approach is particularly useful for:

  • AJAX-powered dynamic content updates
  • Optimizing performance by sending only the necessary HTML fragments
  • More info here