在主题之间共享部分内容的简单方法是什么。资产是可能的,但我在整个部分上都有问题。我有一个由子域策略/逻辑管理/激活的多主题网站。
解决方案 / ** * *在此组件的上下文中渲染请求的局部, *有关用法,请参见Cms \ Classes \ Controller @ renderPartial。 * /
/**
* @param $themeName
* @param $partialName
* @param $data
* @return mixed
* @throws \Cms\Classes\CmsException
*/
public function renderThemePartial($partialName, $themeName, $data)
{
$theme = Theme::getActiveTheme();
if($themeName) {
$theme = Theme::load($themeName);
}
$controller = new Controller($theme);
return $controller->renderPartial($partialName, $data);
}
/**
*
* Renders a requested content in context of this component,
* see Cms\Classes\Controller@renderContent for usage.
*/
/**
* @param $themeName
* @param $contentName
* @param $data
* @return string
* @throws \Cms\Classes\CmsException
*/
public function renderThemeContent($contentName, $themeName, $data)
{
$theme = Theme::getActiveTheme();
if($themeName) {
$theme = Theme::load($themeName);
}
$controller = new Controller($theme);
return $controller->renderContent($contentName, $data);
}
public function registerMarkupTags()
{
return [
'functions' => [
'partial_from_theme' => [$this, 'themePartial'],
'content_from_theme' => [$this, 'themeContent'],
],
'filters' => [
'theme_asset' => [$this, 'themeUrl']
]
];
}
/**
* @param $requested
* @return string
*/
public function themeUrl($requested)
{
$asset = $requested[0];
$theme = $requested[1];
$theme = Theme::load($theme);
$themeDir = $theme->getDirName();
if (is_array($asset)) {
$_url = Url::to(CombineAssets::combine($asset, themes_path().'/'.$themeDir));
}
else {
$_url = Config::get('cms.themesPath', '/themes').'/'.$themeDir;
if ($asset !== null) {
$_url .= '/'.$asset;
}
$_url = Url::asset($_url);
}
return $_url;
}
/**
* @param $partialName
* @param null $themeName
* @param array $parameters
* @return mixed
* @throws \Cms\Classes\CmsException
*/
public function themePartial($partialName, $themeName = null, $parameters = [])
{
return $this->renderThemePartial($partialName, $themeName, $parameters);
}
/**
* @param $contentName
* @param null $themeName
* @param array $parameters
* @return string
* @throws \Cms\Classes\CmsException
*/
public function themeContent($contentName, $themeName = null, $parameters = [])
{
return $this->renderThemeContent($contentName, $themeName, $parameters);
}
答案 0 :(得分:0)
我想您可以在这里使用Plugin component
和add component to page
。{p>
您需要在组件中定义部分use its partial
。
然后像下面的页面一样使用[ you can add as many as you like ]
,现在使用partial
this same thing you can do in other themes as well.
会change partial
就像它的affect in all other themes
shared across multiple themes.
是您Down side
,您需要通过ftp或其他方式手动更改该文件。
嗯
您可以为其添加自定义树枝功能
您可以在任何插件中添加此代码
can not change its content from backend
现在当您想使用部分主题时,就可以使用主题
public function registerMarkupTags()
{
return [
'functions' => [
'theme_partial' => [$this, 'themePartial'],
]
];
}
public function themePartial($partialName, $themeName = null, $vars = [])
{
$theme = Theme::getActiveTheme();
if($themeName) {
$theme = Theme::load($themeName);
}
$template = call_user_func([Partial::class, 'load'], $theme, $partialName);
$partialContent = $template->getTwigContent();
$html = Twig::parse($partialContent, $vars);
return $html;
}
{{ theme_partial('call_from_other_theme', 'stemalo' ,{'name':'hardik'}) }} ^ Your theme name here.
内容
themes/stemalo/partials/call_from_other_theme.htm
这样,您可以使用其他主题的部分内容。
description = "Shared Partial." [viewBag] == <div id="shared_partial"> <h1>Another Theme Partial : {{name}}</h1> </div>
可能只是您需要传递主题名称,而`dynamic可以传递变量作为主题名称,以便它可以选择您喜欢的任何内容。
如有疑问,请发表评论。