Setting spaceless in presenter

Backer | 77

I wrap all my @layout-latte-files with {spaceless}-tags. But while developing I like not to have spaceless enabled.

Is it possible to enable spaceless in a template from the presenter-class (e.g. using debug-mode), so I do not have to manually modify the latte-template-files?

Member | 210

Maybe you can just rewrite spaceless while developing?

function beforeRender() {
    if (\Tracy\Debugger::isEnabled() === true) {
        $this->template->addFilter('spaceless', fn(string $s) => $s); // disable spaceless
Marek Bartoš
Nette Blogger | 1212
{if \Tracy\Debugger::$productionMode === true}
	{include foo|spaceless}
	{include foo}

But probably not worth it. You will break space-sensitive code (like <pre><code> tags) and webserver should do fairly better job compressing the page anyway.

Last edited by Marek Bartoš (2024-04-14 13:52)