Prestashop cms 页面 json 内容
Prestashop cms page json content
我正在尝试使用 api 从我朋友的 wordpress 获取 CMS 页面内容。
这很好用,我可以使用 css.
自定义内容
但我知道你不应该在控制器中插入 html,有没有办法为此做 .tpl 文件,然后调用标题和内容
或者
如果您也能以某种方式将此内容也提供给管理员,那就更好了,但我认为目前这是不可能的?
但是,其他 cms 页面应该可以正常工作。
我目前在 CmsController.php 内部函数 initContent:
if($this->cms->meta_title == 'mycmspage')
{
$ch = curl_init();
$timeout = 5;
$url = 'http://friendurl.com/wp-json/wp/v2/pages/xxx';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
$obj = json_decode($data, TRUE);
$this->cms->content = '<h2 class="myheader">'.$obj['title']['rendered'].'</h2><article class="myarticle">'. $obj['content']['rendered'].'</article>';
}
使用 prestashop 1.6.1
是的,您可以设置 smarty 变量并获取模板内容。
$obj = json_decode($data, TRUE);
$this->context->smarty->assign(array(
'mycms_title' => $obj['title']['rendered'],
'mycms_content' => $obj['content']['rendered']
));
$this->cms->content = $this->context->smarty->fetch('path_to_your_tpl_file');
类似这样的事情也可以通过管理控制器来实现。取决于您所在的管理页面类型(列表、查看、添加、编辑等),但默认情况下它是一种列表。所以你可以覆盖renderList()
方法来显示它。
AdminYourModController extends ModuleAdminController {
public function renderList() {
// your curl code
$obj = json_decode($data, TRUE);
$this->context->smarty->assign(array(
'mycms_title' => $obj['title']['rendered'],
'mycms_content' => $obj['content']['rendered']
));
return $this->context->smarty->fetch('path_to_your_tpl_file');
}
}
我正在尝试使用 api 从我朋友的 wordpress 获取 CMS 页面内容。 这很好用,我可以使用 css.
自定义内容但我知道你不应该在控制器中插入 html,有没有办法为此做 .tpl 文件,然后调用标题和内容 或者 如果您也能以某种方式将此内容也提供给管理员,那就更好了,但我认为目前这是不可能的?
但是,其他 cms 页面应该可以正常工作。
我目前在 CmsController.php 内部函数 initContent:
if($this->cms->meta_title == 'mycmspage')
{
$ch = curl_init();
$timeout = 5;
$url = 'http://friendurl.com/wp-json/wp/v2/pages/xxx';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
$obj = json_decode($data, TRUE);
$this->cms->content = '<h2 class="myheader">'.$obj['title']['rendered'].'</h2><article class="myarticle">'. $obj['content']['rendered'].'</article>';
}
使用 prestashop 1.6.1
是的,您可以设置 smarty 变量并获取模板内容。
$obj = json_decode($data, TRUE);
$this->context->smarty->assign(array(
'mycms_title' => $obj['title']['rendered'],
'mycms_content' => $obj['content']['rendered']
));
$this->cms->content = $this->context->smarty->fetch('path_to_your_tpl_file');
类似这样的事情也可以通过管理控制器来实现。取决于您所在的管理页面类型(列表、查看、添加、编辑等),但默认情况下它是一种列表。所以你可以覆盖renderList()
方法来显示它。
AdminYourModController extends ModuleAdminController {
public function renderList() {
// your curl code
$obj = json_decode($data, TRUE);
$this->context->smarty->assign(array(
'mycms_title' => $obj['title']['rendered'],
'mycms_content' => $obj['content']['rendered']
));
return $this->context->smarty->fetch('path_to_your_tpl_file');
}
}