walkor / walkor/webman

Handling Twig extensions

Open
#260 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
2.7k
Forks
251
PR merge metrics
No merged PRs in 30d

Description

Would be great if we could add extensions somehow in config without modifying the actual /support/view/Twig.php file

>>

public static function render($template, $vars, $app = null)
{
static $views = [], $view_suffix;
$view_suffix = $view_suffix ? : \config('view.view_suffix', 'html');
$app = $app === null ? \request()->app : $app;
if (!isset($views[$app])) {
$view_path = $app === '' ? \app_path(). '/view/' : \app_path(). "/$app/view/";
$views[$app] = new Environment(new FilesystemLoader($view_path), \config('view.options', []));

$views[$app]->addExtension(new \Jasny\Twig\DateExtension());
$views[$app]->addExtension(new \Jasny\Twig\PcreExtension());
$views[$app]->addExtension(new \Jasny\Twig\TextExtension());
$views[$app]->addExtension(new \Jasny\Twig\ArrayExtension());
}
$vars = \array_merge(static::$_vars, $vars);
$content = $views[$app]->render("$template.$view_suffix", $vars);
static::$_vars = [];
return $content;
}

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with /support/view/Twig.php, especially the Environment setup and the hard-coded addExtension calls. Read how view.options is loaded through config and determine how extensions could be supplied without editing this file. Done means extensions can be configured by an application while the existing built-in extensions continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.