Crow

Yet another template engine for PHP

This project is maintained by Corviz

Crow template engine - extending

Sometimes, you will want to create your own methods. To do so, follow the steps bellow:

1 - Create your method class:

You can create your class wherever you like in your application. The only requisite is that you extend Corviz\Crow\Method

namespace App\Template\CustomMethods;

use Corviz\Crow\Method;

class TestMethod extends Method
{
    /**
     * @inheritDoc
     */
    public function toPhpCode(?string $parametersCode = null): string
    {
        return "<?php echo 'This is just a test!'; ?>";
    }
}

$parametersCode will carry the provided php code between parenthesis in your template. For example, if you have a @if call in your template:

@if ($variable == 'value')
...

The variable $parametersCode will contain the string $variable == 'value'

2 - Register your method

The first parameter will be the method signature, the second the name of the class that will be used:

Crow::addMethod('mytestmethod', \App\Template\CustomMethods\TestMethod::class);

3 - Use it!

<div class="contents">
    @mytestmethod
</div>

As simple as that :)