-
Notifications
You must be signed in to change notification settings - Fork 9
Creating frontend templates with variants
BlackCat can handle templates with variants. This means, you may create ONE template which has variants for home (welcome) page, news pages, gallery pages, WYSIWYG pages, and so on.
Note: Don't provide TOO much variants, this might irritate the user.
Every template should have the following directory structure, even if it does not provide variants by default:
./templates
/<templatename>
/index.php
/css
/default default variant
/templates
/default default variant
/index.tpl
For every variant, create a subfolder with the name of the variant, like this (example):
./templates
/<templatename>
/index.php
/css
/default default variant
/gallery
/templates
/default default variant
/index.tpl
/gallery
/index.tpl
Now it's quite easy to create an index.php
located in <templatename>
folder which supports variants:
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
* @author Black Cat Development
* @copyright 2013, Black Cat Development
* @link http://blackcat-cms.org
* @license http://www.gnu.org/licenses/gpl.html
* @category CAT_Templates
* @package <templatename>
*
*/
if (defined('CAT_PATH')) {
if (defined('CAT_VERSION')) include(CAT_PATH.'/framework/class.secure.php');
} elseif (file_exists($_SERVER['DOCUMENT_ROOT'].'/framework/class.secure.php')) {
include($_SERVER['DOCUMENT_ROOT'].'/framework/class.secure.php');
} else {
$subs = explode('/', dirname($_SERVER['SCRIPT_NAME'])); $dir = $_SERVER['DOCUMENT_ROOT'];
$inc = false;
foreach ($subs as $sub) {
if (empty($sub)) continue; $dir .= '/'.$sub;
if (file_exists($dir.'/framework/class.secure.php')) {
include($dir.'/framework/class.secure.php'); $inc = true; break;
}
}
if (!$inc) trigger_error(sprintf("[ <b>%s</b> ] Can't include class.secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
// Optional set some values for output....
$dwoodata = array();
// get variant to use
$variant = CAT_Helper_Page::getPageSettings($page_id,'internal','template_variant');
if(!$variant)
$variant = 'default';
$parser->setPath(CAT_TEMPLATE_DIR.'/templates/'.$variant);
$parser->setFallbackPath(CAT_TEMPLATE_DIR.'/templates/default');
// Print output
$parser->output('index.tpl', $dwoodata );
BlackCat CMS automatically creates a variants select box if it finds a list of variants configured in the info.php
of the template. So add your variants like this:
$template_variants = array( 'default', 'gallery' );
BlackCat CMS has an easy naming convention for autoloading. So the easiest way to autoload the variant's CSS - located in ./templates/<templatename>/css/<variantname>
- is to name it template.css
.
If you need more complex logic or different file names, use the headers.inc.php
.
Note: If you don't need a different CSS for the variant, you don't have to create a subfolder under css
.
get_page_footers()
completely replaces the old method register_frontend_modfiles_body()
.
Just add the function call directly before the closing </body>
-Tag of the template:
<html>
<head>
...more...
</head>
<body>
...
<?php get_page_footers(); ?>
</body>
</html>
Or, for Dwoo based templates:
{get_page_footers()}
For backend templates (which are always Dwoo based), use
{get_page_footers('backend')}
The function is backward compatible and automatically loads the following files of all modules used on the current page:
<Module>/frontend_body.js
In addition, every module can have a file named footers.inc.php
to define additional files.
The basics are the same as described in get_page_headers(). The file should define an array named $mod_footers
.
Of course, neither CSS files can be loaded nor META-settings can be made in the footer. But it is possible to load additional JavaScripts here.
Example:
$mod_footers = array(
'frontend' => array(
'script' => array(
array(
'alert("hello world!");'
),
),
),
);