我正在构建一个程序包,它使用带有自定义块模板的页面列表块,根据页面属性在地图上显示位置。
我想为地图页面和位置页面加载页面模板文件,以便可以在模板文件中构建这些页面的布局。由于此软件包不包含主题,因此我很难让Concrete5从软件包中加载模板文件。页面类型和模板都在Concrete5中列出,并且在创建新页面时会正确加载composer表单。不幸的是,该包中模板文件的布局未加载,因此我得到的只是已安装主题的默认模板布局。任何帮助将不胜感激!
这是基于Concrete5.7.5.13
构建的这是我的文件结构:
[Package root]
- blocks
- - page_list
- - - templates
- - - - page_list_map.php
- controller.php
- controllers
- - single_page
- - - dashboard
- - - - locations_map_page_list
- - - - - settings
- - - - locations_map_page_list.php
- page_templates
- - location.php
- - locations_map.php
- single_pages
- - dashboard
- - - locations_map_page_list
- - - - settings.php
- - - locations_map_page_list.php
在我的程序包控制器中,我添加了代码来设置页面模板和页面类型。
添加模板的功能(这将加载模板文件)
public function addPageTemplates($pkg) {
if (!is_object(PageTemplate::getByHandle('locations_map'))){
$pageTemplate = PageTemplate::add('locations_map', 'Locations Map (Default)', 'full.png', $pkg);
}
if (!is_object(PageTemplate::getByHandle('location'))){
$pageTemplate = PageTemplate::add('location', 'Location (Default)', 'full.png', $pkg);
}
}
添加页面类型的功能
public function addPageTypes($pkg) {
// Locations Map Page Type
$mapPageType = PageType::getByHandle('lmpl_locations_map');
if (!is_object($mapPageType)) {
$mapPageTemplate = PageTemplate::getByHandle('locations_map'); // Should match the template file name without the extension
$mapPageType = PageType::add(
array(
'handle' => 'lmpl_locations_map',
'name' => 'Locations Map', //Note: it does not appear you can pass the t() function in the name
'defaultTemplate' => $mapPageTemplate, // This should load the template file from the package
'allowedTemplates' => 'C', //A is all, C is selected only, X is not selected only. Defaults to A if key is not included
'templates' => array($mapPageTemplate), //So, in this case, with C above, ONLY the template listed can be used
'ptLaunchInComposer' => true, //optional, defaults to false, but need to set to true to display the composer form
'ptIsFrequentlyAdded' => false, //optional, defaults to false. Determines whether or not it shows up in the add page type frequent list
'ptPublishTargetTypeID' => 1,
'cParentID' => 1
),
$pkg //this would come from the install or upgrade function usually
);
// Code to setup composer omitted...
// Location Page Type
$locPageType = PageType::getByHandle('lmpl_location');
if (!is_object($location)) {
$locPageTemplate = PageTemplate::getByHandle('location'); // Should match the template file name without the extension
$locPageType = PageType::add(
array(
'handle' => 'lmpl_location',
'name' => 'Location',
'defaultTemplate' => $locPageTemplate, // This should load the template file from the package
'allowedTemplates' => 'C', //A is all, C is selected only, X is not selected only. Defaults to A if key is not included
'templates' => array($locPageTemplate), //So, in this case, with C above, ONLY the template listed can be used
'ptLaunchInComposer' => true, //optional, defaults to false, but need to set to true to display the composer form
'ptIsFrequentlyAdded' => false, //optional, defaults to false. Determines whether or not it shows up in the add page type frequent list
'ptPublishTargetTypeID' => 1,
'cParentID' => 1
),
$pkg //this would come from the install or upgrade function usually
);
// Code to setup composer omitted...
}
现在,所有模板文件都被编码为在段落中显示它们自己的名称,以便我可以看到它们是否正确加载,但是我所得到的只是活动主题中的默认页面模板。一旦使它起作用,我将为这些页面添加默认布局,以便从该程序包安装的页面属性中显示位置名称,地址和地图。
我试图避免为客户端进行大量设置,这就是为什么我不只是设置一个块,因为这将迫使编辑器将这些块添加到页面中。该项目的规范还指出,每个位置都需要有自己的可搜索页面,因此,使用数据库表提取数据会带来新的问题。
如果无法加载页面模板文件,我愿意提出一种更好的方法的建议,但是我很快会达到预算的时间,因此,我希望尽可能加载模板文件。 。谢谢您的帮助!