Yet another template engine for PHP
This project is maintained by Corviz
Sometimes, you will want to create your own methods. To do so, follow the steps bellow:
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'
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);
<div class="contents">
@mytestmethod
</div>
As simple as that :)