Content management system Silverstripe-手动将模板分配给控制器
目前,我正在使用具有控制器规则的自定义Silverstripe控制器:Content management system Silverstripe-手动将模板分配给控制器,content-management-system,silverstripe,Content Management System,Silverstripe,目前,我正在使用具有控制器规则的自定义Silverstripe控制器: --- Name: myroutes After: framework/routes#coreroutes --- Director: rules: 'category/$Action/$Slug': 'Category_Controller' 控制器如下所示: class Category_Controller extends Page_Controller { public function sho
---
Name: myroutes
After: framework/routes#coreroutes
---
Director:
rules:
'category/$Action/$Slug': 'Category_Controller'
控制器如下所示:
class Category_Controller extends Page_Controller {
public function show($arguments) {
echo "Slug: " . $arguments->param("Slug");
}
}
当我在浏览器中打开URL时
然后,输出看起来像这样:“Slug:mobile”
我只是想知道如何使用文件夹“themes/templates/Layout”中的Category.ss模板来呈现输出。当然,还应该包括Page.ss中的容器html(带页眉/页脚)。与往常一样,在布局文件夹中有一个自定义页面控制器/类和相应的模板
我刚试过这个:
public function show($arguments) {
echo $this->renderWith("Category");
}
它使用Category.ss呈现输出,但没有容器html
谢谢你的帮助。
当做
Florian您还可以将数组传递给
renderWith()
,它将尝试遍历数组,直到找到模板
让我们假设$this->renderWith(数组('Category','Page')代码>
它将首先查找名为Category.ss
的模板,但找不到它(在templates文件夹中,而不是在layout文件夹中),然后查找Page.ss
并使用它。
现在它在页面内点击$Layout
,ss
并再次检查Layout文件夹内的数组,现在它将找到类别.ss
,如果我答对了问题,这正是您要找的
如果不想执行返回$this->renderWith()
您也可以只做返回$this
和silverstripe将获得您调用的操作和$this的类层次结构,并将其用作renderWith()的数组。
因此,如果您的类是Category\u Controller>Page\u Controller>ContentController
,那么数组将如下所示:
array(
'Category_show', // because your action is show
'Category',
'Page_show',
'Page',
'ContentController_show',
'ContentController',
)
(我不能100%确定它是否还包括Page_show和ContentController_show。)您还可以将数组传递给renderWith()
,它将尝试遍历数组,直到找到模板
让我们假设$this->renderWith(数组('Category','Page')代码>
它将首先查找名为Category.ss
的模板,但找不到它(在templates文件夹中,而不是在layout文件夹中),然后查找Page.ss
并使用它。
现在它在页面内点击$Layout
,ss
并再次检查Layout文件夹内的数组,现在它将找到类别.ss
,如果我答对了问题,这正是您要找的
如果不想执行返回$this->renderWith()
您也可以只做返回$this
和silverstripe将获得您调用的操作和$this的类层次结构,并将其用作renderWith()的数组。
因此,如果您的类是Category\u Controller>Page\u Controller>ContentController
,那么数组将如下所示:
array(
'Category_show', // because your action is show
'Category',
'Page_show',
'Page',
'ContentController_show',
'ContentController',
)
(我不能100%确定它是否还包括Page_show和ContentController_show。)我也发现这段代码可以工作:$ssv=new SSViewer(“Page”)$ssv->setTemplateFile(“布局”、“类别”);echo$this->renderWith($ssv);我还发现这段代码可以工作:$ssv=newssviewer(“Page”)$ssv->setTemplateFile(“布局”、“类别”);echo$this->renderWith($ssv);