Both Twig and Stempler engines include support for Spiral\Views\ProcessorInterface
which works similar to http middlewares and modifies raw view source before or after it been pushed though render engine.
interface ProcessorInterface
{
/**
* @param EnvironmentInterface $environment
* @param ViewSource $view
* @param string $code
*
* @return string
*/
public function modify(
EnvironmentInterface $environment,
ViewSource $view,
string $code
): string;
}
Descriptions of existed view processors.
Replaces all [[strings]]
with locale specific translation.
Note that by default View environment depends on current locale value, switching language will cause new cache location and view recompilation.
Replaces all @{constructs|default}
constructions with environment dependency value, for example:
View config:
'environment' => [
'language' => ['translator', 'getLocale'],
'basePath' => ['http', 'basePath'],
/*{{environment}}*/
],
View:
Current language @{language}
Creates set of macros to handle php extraction for toolkit and EvaluateProcessor.
This is internal plugin.
Provides ability to execute php blocks with "#compile" comment in compilation mode (only once).
This view is compiled at <?= date('c') #compile ?>
Blocks marked as #compile does not have access to view data.
Replaces extra lines in view and drops empty html attributes.