Twig 覆盖bolt.cms中的后端模板
我试图覆盖位于Twig 覆盖bolt.cms中的后端模板,twig,bolt-cms,Twig,Bolt Cms,我试图覆盖位于供应商/bolt/bolt/app/view/twig/editcontent/fields/\u block.twig中的模板文件(我想替换“块选择”下拉列表)。关于、和,这在默认情况下不受支持,因此我必须为此编写扩展。所以我试了一下: 后端块选择扩展: namespace Bundle\Site; use Bolt\Filesystem\Adapter\Local; use Bolt\Filesystem\Filesystem; use Silex\Application;
供应商/bolt/bolt/app/view/twig/editcontent/fields/\u block.twig中的模板文件(我想替换“块选择”下拉列表)。关于、和,这在默认情况下不受支持,因此我必须为此编写扩展。所以我试了一下:
后端块选择扩展:
namespace Bundle\Site;
use Bolt\Filesystem\Adapter\Local;
use Bolt\Filesystem\Filesystem;
use Silex\Application;
use Bolt\Extension\SimpleExtension;
class BackendBlockSelectionExtension extends SimpleExtension
{
public function getServiceProviders()
{
return [
$this,
new BackendBlockSelectionProvider(),
];
}
}
namespace Bundle\Site;
use Bolt\Filesystem\Adapter\Local;
use Bolt\Filesystem\Filesystem;
use Silex\Application;
use Silex\ServiceProviderInterface;
class BackendBlockSelectionProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
$side = $app['config']->getWhichEnd();
if ($side == 'backend') {
$path = __DIR__ . '/App/templates/Backend';
$filesystem = $app['filesystem'];
$filesystem->mountFilesystem('bolt', new Filesystem(new Local($path)));
$app['twig.loader.bolt_filesystem'] = $app->share(
$app->extend(
'twig.loader.bolt_filesystem',
function ($filesystem, $app) {
$path = __DIR__ . 'src/App/templates/Backend/';
$filesystem->prependPath($path, 'bolt');
return $filesystem;
}
)
);
}
}
public function boot(Application $app)
{
}
}
后端块选择提供程序:
namespace Bundle\Site;
use Bolt\Filesystem\Adapter\Local;
use Bolt\Filesystem\Filesystem;
use Silex\Application;
use Bolt\Extension\SimpleExtension;
class BackendBlockSelectionExtension extends SimpleExtension
{
public function getServiceProviders()
{
return [
$this,
new BackendBlockSelectionProvider(),
];
}
}
namespace Bundle\Site;
use Bolt\Filesystem\Adapter\Local;
use Bolt\Filesystem\Filesystem;
use Silex\Application;
use Silex\ServiceProviderInterface;
class BackendBlockSelectionProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
$side = $app['config']->getWhichEnd();
if ($side == 'backend') {
$path = __DIR__ . '/App/templates/Backend';
$filesystem = $app['filesystem'];
$filesystem->mountFilesystem('bolt', new Filesystem(new Local($path)));
$app['twig.loader.bolt_filesystem'] = $app->share(
$app->extend(
'twig.loader.bolt_filesystem',
function ($filesystem, $app) {
$path = __DIR__ . 'src/App/templates/Backend/';
$filesystem->prependPath($path, 'bolt');
return $filesystem;
}
)
);
}
}
public function boot(Application $app)
{
}
}
这似乎可以完成任务,但我遇到了一个我完全不理解的错误:the“bolt://app/theme_defaults“目录不存在。
因此,我的最后一个问题是:有没有人有一些示例代码如何在不接触供应商
文件夹的情况下覆盖/修改供应商/bolt/bolt/app/view/twig/editcontent/fields/_block.twig
在扩展类中,覆盖受保护的函数registerTwigPaths()
函数如下:
protected function registerTwigPaths()
{
if ($this->getEnd() == 'backend') {
return [
'view' => ['position' => 'prepend', 'namespace' => 'bolt']
];
}
return [];
}
private function getEnd()
{
$backendPrefix = $this->container['config']->get('general/branding/path');
$end = $this->container['config']->getWhichEnd();
switch ($end) {
case 'backend':
return 'backend';
case 'async':
// we have async request
// if the request begin with "/admin" (general/branding/path)
// it has been made on backend else somewhere else
$url = '/' . ltrim($_SERVER['REQUEST_URI'], $this->container['paths']['root']);
$adminUrl = '/' . trim($backendPrefix, '/');
if (strpos($url, $adminUrl) === 0) {
return 'backend';
}
default:
return $end;
}
}
现在,您可以在extensions目录中创建一个视图目录,在该目录中,您可以像Bolt的默认值一样在结构中定义模板。我将从复制和覆盖开始。谢谢。经过一番努力,一切都如期进行。最后的路径是:
extensions/lulubu/pretty block selection/view/editcontent/fields/\u block.twig