Volt Compiler missing PHP_EOL
Hi,
Expected and Actual Behavior
There seems to be an issue with how Volt Compiler creates the PHP templates regarding the expected and actual result with echoes that end on a PHP_EOL character.
i.e. if we create this template:
Hello {{ world }}
Hello {{ world }}
If we execute it with $world = "world"; you should expect to have the following result in output:
Hello world
Hello world
But this is not the reality, volt generates the following compiled template:
Hello <?= $hello ?>
Hello <?= $hello ?>
And the actual result is this:
Hello worldHello world
And that's not our expected output; PHP does not output the PHP_EOL after the first echo, idk why but php does it this way. I've tested this very same template using twig to see if it had the same issue, and when it generate that template, it manually adds an echo of a PHP_EOL.
This does not happens if you add another character after the echo:
Hello {{ hello }}!
Hello {{ hello }}!
This template compiles to:
Hello <?= $hello ?>!
Hello <?= $hello ?>!
and outputs:
Hello world!
Hello world!
This is not an important issue when you are using Volt to output HTML, but when you are creating text files, whatever else (which I do) it is annoying to add line separators after the {{ }} if you intend to jump a line that should be already jumped.
Thanks for your time, Federico.
Provide minimal script to reproduce the issue
PHP:
<?php
use Phalcon\Mvc\View\Engine\Volt\Compiler as VoltCompiler;
// Create a compiler
$compiler = new VoltCompiler();
// Compile a template in a file specifying the destination file
$compiler->compileFile(
'layouts/main.volt',
'cache/layouts/main.volt.php'
);
// Compile a template in a file based on the options passed to the compiler
$compiler->compile(
'layouts/main.volt'
);
$hello = "world";
// Require the compiled templated (optional)
require $compiler->getCompiledTemplatePath();
Volt template:
Hello {{ hello }}
Hello {{ hello }}
Details
- Phalcon version: (
php --ri phalcon)
phalcon
Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 3.2.1
Build Date => Jul 17 2017 13:04:30
Powered by Zephir => Version 0.9.9-868cb1f92b
Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.events => On => On
phalcon.orm.virtual_foreign_keys => On => On
phalcon.orm.column_renaming => On => On
phalcon.orm.not_null_validations => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.enable_literals => On => On
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.disable_assign_setters => Off => Off
- PHP Version: (
php -v)
PHP 5.6.30 (cli) (built: Feb 7 2017 16:18:37)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
- Operating System:
macOS 10.12.6 - Installation type:
Compiling from source - Zephir version (if any):
- Server:
none required - Other related info (Database, table schema):
Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues