Kcko
3/7/2018 - 4:19 PM

Macro - ukázkové

Nette - macro

<?php

namespace App\Utils;

use Latte;

class Macros extends Latte\Macros\MacroSet
{

    public static function install(Latte\Compiler $compiler)
    {
        $set = new static($compiler);

        $set->addMacro('currency', array($set, 'macroCurrency'));

        return $set;
    }


    public function macroCurrency(Latte\MacroNode $node, Latte\PhpWriter $writer)
    {
        return $writer->write(
            'echo \App\Utils\Macros::renderMacroCurrency(%node.word)'
        );
    }


    public static function renderMacroCurrency($currency = NULL)
    {
        $currency = $currency ?: self::$currency;

        switch ($currency) {
            case 'EUR': return "€";
            default: return 'Kč';
        }
    }

}
Config:
latte:
    macros:
        - App\Utils\Macros