Skip to content
Permalink
Browse files

added macro n:nonce

  • Loading branch information
dg committed Jan 12, 2020
1 parent 52f6873 commit 9d623aecb5156de1599412dc3b12a18b44311cc9
Showing with 32 additions and 0 deletions.
  1. +2 −0 src/Latte/Macros/CoreMacros.php
  2. +30 −0 tests/Latte/CoreMacros.nonce.phpt
@@ -71,6 +71,8 @@ public static function install(Latte\Compiler $compiler): void
$me->addMacro('varType', [$me, 'macroVarType'], null, null, self::ALLOWED_IN_HEAD);
$me->addMacro('templateType', [$me, 'macroTemplateType'], null, null, self::ALLOWED_IN_HEAD);
$me->addMacro('templatePrint', [$me, 'macroTemplatePrint'], null, null, self::ALLOWED_IN_HEAD);

$me->addMacro('nonce', null, null, 'echo $this->global->coreNonce ? " nonce=\"{$this->global->coreNonce}\"" : "";');
}


@@ -0,0 +1,30 @@
<?php

/**
* Test: n:nonce
*/

declare(strict_types=1);

use Tester\Assert;


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


$latte = new Latte\Engine;
$latte->setLoader(new Latte\Loaders\StringLoader);
$latte->addProvider('coreNonce', null);

Assert::match(
'<script></script>',
$latte->renderToString('<script n:nonce></script>')
);


$latte->addProvider('coreNonce', 'djsdgidk');

Assert::match(
'<script nonce="djsdgidk"></script>',
$latte->renderToString('<script n:nonce></script>')
);

0 comments on commit 9d623ae

Please sign in to comment.
You can’t perform that action at this time.