Skip to content

Commit

Permalink
added macro {php} as a future replacement for {?}
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 6, 2015
1 parent 71c5175 commit 33c6c24
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Latte/Macros/CoreMacros.php
Expand Up @@ -79,6 +79,7 @@ public static function install(Latte\Compiler $compiler)
$me->addMacro('use', array($me, 'macroUse'));
$me->addMacro('contentType', array($me, 'macroContentType'));
$me->addMacro('status', array($me, 'macroStatus'));
$me->addMacro('php', array($me, 'macroExpr'));

$me->addMacro('class', NULL, NULL, array($me, 'macroClass'));
$me->addMacro('attr', NULL, NULL, array($me, 'macroAttr'));
Expand Down Expand Up @@ -374,7 +375,7 @@ public function macroVar(MacroNode $node, PhpWriter $writer)
*/
public function macroExpr(MacroNode $node, PhpWriter $writer)
{
return $writer->write(($node->name === '?' ? '' : 'echo ') . '%modify(%node.args)');
return $writer->write(($node->name === '=' ? 'echo ' : '') . '%modify(%node.args)');
}


Expand Down
28 changes: 28 additions & 0 deletions tests/Latte/macros.php.phpt
@@ -0,0 +1,28 @@
<?php

/**
* Test: Latte\Engine: {php}
*/

use Tester\Assert;


require __DIR__ . '/../bootstrap.php';


$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);

Assert::match('%A%
<?php $a = \'test\' ? array() : NULL ;
', $latte->compile('
{php}
{php $a = test ? []}
'));

Assert::match('%A%
<?php $a = \'test\' ? array() : NULL ;
', $latte->compile('
{?}
{? $a = test ? []}
'));

2 comments on commit 33c6c24

@fprochazka
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I like it :)

@Vrtak-CZ
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like

Please sign in to comment.