在 Silverstripe 4 中访问和输出 $ElementalArea
Accessing & Outputting $ElementalArea in Silverstripe 4
在 Silverstripe 4 项目中,我们在 PageController.php
下使用以下方法将页面内容输出为 JSON:
class PageController extends ContentController
{
private static $allowed_actions = array(
'json'
);
public function json(HTTPRequest $request)
{
$data = array();
$data['ID'] = $this->ID;
$data['Title'] = $this->Title;
$data['Breadcrumbs'] = $this->obj('Breadcrumbs')->forTemplate();
$data['Content'] = $this->obj('Content')->forTemplate();
$this->response->addHeader('Content-Type', 'application/json');
return json_encode($data);
}
}
现在我想对 运行 Elemental module 页面做同样的事情。 Elementals 允许页面内容由许多动态/可配置块生成。
为了访问元素,我使用了以下模板代码:$ElementalArea
- returns 生成了 HTML。
我需要用 returns 由 $ElementalArea
生成的 HTML 替换以下行:
$data['Content'] = $this->obj('Content')->forTemplate();
我不确定执行此操作的正确方法,如有任何建议,我们将不胜感激。
完全一样 - $this->ElementalArea()->forTemplate()
.
在 Silverstripe 4 项目中,我们在 PageController.php
下使用以下方法将页面内容输出为 JSON:
class PageController extends ContentController
{
private static $allowed_actions = array(
'json'
);
public function json(HTTPRequest $request)
{
$data = array();
$data['ID'] = $this->ID;
$data['Title'] = $this->Title;
$data['Breadcrumbs'] = $this->obj('Breadcrumbs')->forTemplate();
$data['Content'] = $this->obj('Content')->forTemplate();
$this->response->addHeader('Content-Type', 'application/json');
return json_encode($data);
}
}
现在我想对 运行 Elemental module 页面做同样的事情。 Elementals 允许页面内容由许多动态/可配置块生成。
为了访问元素,我使用了以下模板代码:$ElementalArea
- returns 生成了 HTML。
我需要用 returns 由 $ElementalArea
生成的 HTML 替换以下行:
$data['Content'] = $this->obj('Content')->forTemplate();
我不确定执行此操作的正确方法,如有任何建议,我们将不胜感激。
完全一样 - $this->ElementalArea()->forTemplate()
.