-
Notifications
You must be signed in to change notification settings - Fork 0
Dev.Theme Helpers
asset
assetLocale
assetModule
assetTheme
backbone
basePath
blocks
css
doctype
escape
footScript
ga
headLink
headMeta
headScript
headStyle
headTitle
I18n
I18nModule
I18nTheme
jQuery
js
meta
navigation
nav
navMenu
paginationControl
template
templateComponent
templateModule
templateTheme
url
widget
asset
-- getting URI of an asset folder of module or theme.
Description
Object asset(string $component, string $file)
Parameters
component
Component including asset file, such as theme/default
, module/demo
.
file
File name to build asset URI.
Example
echo $this->asset('theme/default', 'css/style.css');
echo $this->asset('module/demo', 'js/demo.js');
Output:
'http://localhost/Pi/www/asset/theme-default/css/style.css'
'http://localhost/Pi/www/asset/module-demo/js/demo.js'
This helper is used to build locale asset URI inside current theme. It takes three parameters: the first one indicates the file name, the second one indicates the locale file to choose, if it is not set, the system locale will be used, and the third one decides whether to append version for file path.
echo $this->assetLocale('style.css');
echo $this->assetLocale('js1.js', 'Zh-CN', false);
If the system locale is gray:'en'
, and current theme is 'default'
, the code above will output:
'http://localhost/pi/www/asset/theme-default/locale/en/style.css?1355197213'
'http://localhost/pi/www/asset/theme-default/locale/Zh-CN/js1.js'
NOTE: users should check the Append version
checkbox in general configuration page to enable versioning.
assetModule
-- building module asset URI.
Description
string assetModule(string $file, string $module = null)
Parameters
file
File name for building module asset URI.
module
Module name.
Example
echo $this->assetModule('css/style.css');
echo $this->assetModule('js/file1.css', 'demo');
Output:
'http://localhost/Pi/www/asset/module-system/css/style.css'
'http://localhost/Pi/www/asset/module-demo/js/file1.js'
assetTheme
-- building theme asset URI.
Description
string assetTheme(string $file, string $theme = null)
Parameters
file
File name for building theme asset URI.
module
Theme name.
Example
echo $this->assetTheme('css/style.css');
echo $this->assetTheme('image/logo.png', 'dev');
Output:
'http://localhost/Pi/www/asset/theme-default/css/style.css'
'http://localhost/Pi/www/asset/theme-dev/image/logo.png'
This helper is used to load javascript files of backbone. The helper will autoload backbone.min.js
and underscore-min.js
files, and other static files can also be load if their file name is passed.
$this->backbone();
$this->backbone('js1.js');
$this->backbone(array(
'backbone.min.js', 'style.css'
));
basePath
-- building a base path.
Description
string basePath(string $file)
Parameters
file
File name for building base path.
Example
echo $this->basePath('index.php');
echo $this->basePath('asset');
Output:
'http://localhost/Pi/www/index.php'
'http://localhost/Pi/www/asset'
blocks
-- loading blocks of a specified zone.
Description
array|Blocks blocks(string $zone)
Parameters
zone
Zone to load blocks. The value can be 0-8, or null.
Example
$blocks = $this->blocks();
$blocks = $this->blocks(1);
if (isset($blocks[1])) {
foreach ($blocks as $key => $block) {
include $this->template('block.phtml');
}
}
Pi allows users to use bootstrap
to achieve div+css, users only need to include the bootstrap file name and then insert the class name into their HTML tags, the whole front style will come true automatically.
This helper takes two parameters, the first one decides the static files to load, and the second parameter decide whether to load bootstrap.min.css
, and the default value is true.
$this->bootstrap();
$this->bootstrap('css/bootstrap.responsive.min.css');
$this->bootstrap(array(
'css/bootstrap.responsive.css',
'js/bootstrap.js',
));
css
-- loading CSS files.
Description
Object css(string|array $file)
Parameters
file
File name of CSS file or array include file name of CSS files.
Example
$this->css('file.css');
$this->css(array('file1.js', 'file2.js'));
echo $this->headLink();
Output:
'<link href="file.css" media="screen" rel="stylesheet" type="text/css" >'
'<link href="file1.js" media="screen" rel="stylesheet" type="text/css" >'
'<link href="file2.js" media="screen" rel="stylesheet" type="text/css" >'
doctype
-- creating a doctype of HTML
and XHTML
document.
Description
Object doctype(string $doctype)
Parameters
doctype
The doctype allows you to specify one of the following types:
XHTML11
XHTML1_STRICT
XHTML1_TRANSITIONAL
XHTML1_FRAMESET
XHTML1_RDFA
XHTML_BASIC1
HTML4_STRICT
HTML4_LOOSE
HTML4_FRAMESET
HTML5
Example
echo $this->doctype('XHTML1_STRICT');
Output:
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
It is strongly recommended to add escape for output variables, the escape
helper helps user to escape easily.
echo $this->escape($value);
footScript
-- has the same function as headScript
. Generally used in block template.
Description
Object footScript(string $mode = HeadScript::FILE, string $spec = null, string $placement = 'APPEND', array $attrs = array(), string $type = 'text/javascript')
Parameters
mode
May be specified as FILE or SCRIPT.
spec
Url of script.
placement
Can be SET
, APPEND
or PREPEND
.
attrs
Attributes of script.
type
Type of script or array of script attributes.
Example
$this->footScript()->appendFile('/js/scriptaculous.js');
.. _ga:
This helper is used to add GA code for users to get statistical data of their site. It takes only one parameter which is the GA account. And the default account from configuration will be used if it is not set.
$this->ga();
$this->ga('UA-XXXXX-X');
headLink
-- creating and aggregating HTML <link>
element for later retrieval and output in your layout script.
Description
Object headLink(array $attributes = null, $placement = Placeholder\Container\AbstractContainer::APPEND)
Parameters
attributes
Attributes to create link.
Example
echo $this->headLink();
echo $this->headLink(array(
'rel' => 'icon',
'href' => '/img/favicon.ico'),
'PREPEND');
Output of second line:
'<link href="/img/favicon.ico" rel="icon" >'
headMeta
-- creating HTML <meta>
element for later retrieval and output.
Description
Object headMeta(string $content = null, string $keyValue = null, string $keyType = 'name', array $modifiers = array(), string $placement = Placeholder\Container\AbstractContainer::APPEND)
Parameters
content
Content of meta.
keyValue
Content for the key specified in $keyType
.
keyType
May be specified as property
if the doctype has been set to XHTML1_RDFA.
placement
Can be SET
, APPEND
or PREPEND
.
Example
echo $this->headMeta();
echo $this->headMeta()->appendName('keywords', 'framework, PHP, productivity');
Output of second line:
'<meta name="keywords" content="framework, PHP, productivity" >'
headScript
-- creating HTML <script>
element for later retrieval and output.
Description
Object headScript(string $mode = HeadScript::FILE, string $spec = null, string $placement = 'APPEND', array $attrs = array(), string $type = 'text/javascript')
Parameters
mode
May be specified as FILE or SCRIPT.
spec
Url of script.
placement
Can be SET
, APPEND
or PREPEND
.
attrs
Attributes of script.
type
Type of script or array of script attributes.
Example
$this->headScript()->appendFile('/js/scriptaculous.js');
headStyle
-- The HTML <style>
element is used to include CSS stylesheets inline in the HTML <head>
element.
Description
Object headStyle(string $content = null, string $placement = 'APPEND', string|array $attributes = array())
Parameters
content
Stylesheet content.
placement
Decide whether to append, prepend or set the stylesheet content.
attributes
Optional attributes.
Examples
$this->headStyle('style.css', 'APPEND', array('conditional' => 'lt IE 7'));
$this->headStyle()->appendStyle($styles, array('conditional' => 'lt IE 7'));
headTitle
-- creating and storing a HTML <title>
element for later retrieval and output programmatically.
Description
Object headTitle(string $title = null, string $setType = null)
Parameters
title
Name of title.
setType
Type of title, the value can be APPEND
, PREPEND
or SET
.
Example
echo $this->headTitle();
echo $this->headTitle('Zend Framework');
Output of second line:
'<title>Zend Framework</title>'
I18n
-- loading global locale file for application.
Description
object I18n(string $component, string $file)
Parameters
component
Indicating the component or file name data of the translation file.
file
Indicating the locale folder name.
Examples
$this->i18n(array('theme/default', 'main'), 'en');
$this->i18n('usr:date', 'en');
Therefore the following locale files will be loaded:
'D:/wamp/www/pi/usr/theme/default/locale/en/main.csv'
'D:/wamp/www/pi/usr/locale/en/date.csv'
I18nModule
-- loading a module i18n locale file.
Description
Object i18nModule(string $domain, string|null $module = null, string|null $locale = null)
Parameters
domain
Domain name.
module
Module name.
locale
Language name to use.
Examples
$this->i18nModule('block', 'demo', 'en');
Then the following locale file will be loaded:
'D:/wamp/www/pi/usr/demo/locale/en/block.csv'
I18nTheme
-- loading a theme i18n resource.
Description
Object I18nTheme(string $domain, string $theme = null, string $locale = null)
Parameters
domain
Domain name.
theme
Theme name to use.
locale
Language name to use.
Example
$this->i18nTheme('main');
$this->i18nTheme('main', 'default');
$this->i18nTheme('main', null, 'en');
jQuery
-- loading jQuery files or css files, if there is no parameter assigned, it will load jquery.min.js
file as default.
Description
void jQuery(string|array $filename)
Parameters
filename
Name of jQuery file want to load.
Example
$this->jQuery();
$this->jQuery('extension.js');
$this->jQuery(array('example.js', 'jQuery.min.js'));
echo $this->headScript();
Output:
<script type="text/javascript" src="http://localhost/Pi/www/static/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="http://localhost/Pi/www/static/js/jquery/extension.js"></script>
<script type="text/javascript" src="http://localhost/Pi/www/static/js/jquery/example.js"></script>
<script type="text/javascript" src="http://localhost/Pi/www/static/js/jquery/jQuery.min.js"></script>
js
-- loading JavaScript files.
Description
Object js(string|array $file)
Parameters
file
File name of JavaScript file or array include file name of CSS files.
Example
$this->js('file.js');
$this->js(array('file1.js', 'file2.js'));
echo $this->headScript();
Output:
'<script type="text/javascript" src="file.js"></script>'
'<script type="text/javascript" src="file1.js"></script>'
'<script type="text/javascript" src="file2.js"></script>'
meta
-- getting meta data from application's config table.
Description
string|Meta meta(string $name)
Parameters
name
Field name of meta array.
Example
echo $this->meta('sitename');
echo $this->meta('keywords');
Output as default:
'Pi'
'Pi, Web application'
The navigation
helper is used to load a navigation for current module of Pi application.
This helper takes two parameters, the first one is name of navigation to load, it can also be comprehended as section
in general. In Pi, it can be set to front
or admin
to load a front navigation or admin navigation, or name indicate custom navigation defined by users. A front navigation will be used if this parameter is not set. The second parameter is an array and its fields will be used to configure cache.
NOTE: the data used to generate navigation are fetched from core_navigation_node
table, these data are first define in the config/navigation.php
file.
// load a front navigation
$this->navigation('front');
// load a admin navigation and set cache ttl, level and key
$this->navigation('admin', array(
'cache_ttl' => 86400,
'cache_level' => none,
'cache_id' => 'nav_system'));
// render a custom navigation 'cms' if current module is demo
$this->navigation('demo-cms')->render();
Menu
This class is used to operate menu and can be call by $this->navigation()->menu()
.
this setUIClass(string $ulClass);
this setOnlyActiveBranch(bool $flag = true);
this escapeLabels(bool $flag = true);
this setRenderParent(bool $flag = true);
this setPartial(string|array $partial);
string renderMenu(AbstractContainer $container = null, array $options = array());
array renderPair(AbstractContainer $container = null, array $options = array());
string render($AbstractContainer $container = null);
- setUIClass()
Set css class to use for the first 'ul' element when rendering.
$this->navigation('front')->menu()->setUIClass('jd_menu');
- setOnlyActiveBranch()
This method decides whether to render active branch only, the application will only render active branch if set to true.
$this->navigation('front')->menu()->setOnlyActiveBranch();
- escapeLabels()
Indicating whether to escape labels. Its default value is true.
$this->navigation('front')->menu()->escapeLabels();
-
setRenderParents()
$this->navigation('front')->menu()->setRenderParents();
-
setPartial()
-
render()
Rendering menu.
$this->navigation('front')->menu()->render();
Breadcrumbs
This class is used to operate breadcrumbs and can be call by $this->navigation()->breadcrumbs()
.
this setSeparator(string $sepatator);
this setLinkLast(bool $linkLast);
string render(AbstractContainer $container = null);
- setSepatator()
Set breadcrumb separator.
$this->navigation('front')->breadcrumbs()->setSeparator('<span class="divider">></span>');
- setLinkLast()
Deciding whether last page in breadcrumbs should be hyperlinked.
$this->navigation('front')->breadcrumbs()->setLinkLast(true);
- render()
Rendering breadcrumb.
$this->navigation('front')->breadcrumbs()->render();
This class is used to load a global navigation, it will read navigation name from core_config
table, and then render the navigation by calling navigation
helper. Therefore by using this helper in template, users can install custom navigation in admin section and then the custom navigation will be displayed.
The value passed to this method can only be front
and admin
to indicate load front global navigation or administration global navigation, respectively.
Its second parameter is an optional array for setting cache.
$this->nav('front');
$this->nav('admin', array(
'cache_ttl' => 84600,
'cache_id' => 'system_nav',
));
template
-- getting a path of template file if the path is exists.
Description
string template(string $template)
Parameters
template
Template name.
Example
echo $this->template('block.phtml');
Output such as:
'D:/wamp/www/Pi/usr/theme/default/template/block.phtml'
templateModule
-- getting full path of a module template if it exists.
Description
string templateModule(string $template, string $module = null)
Parameters
template
Template name.
module
Module name, if set to null, the current module will be used.
Example
echo $this->templateModule('admin/block-add.phtml', 'system');
echo $this->templateModule('front/login.phtml');
Output such as:
'D:/wamp/www/Pi/usr/module/system/template/admin/block-add.phtml'
'D:/wamp/www/Pi/usr/module/login/template/front/login.phtml'
templateTheme
-- getting full path of a theme template if it exists.
Description
string templateTheme(string $template)
Parameters
template
Template name.
Example
$this->templateTheme('block.phtml');
Output such as:
'D:/wamp/www/Pi/usr/theme/default/template/block.phtml'
url
-- generating an url by given name and route .
Description
Object url(string $name = null, array $params = array(), array $options = array(), boolean $reuseMatchedParams = false)
Parameters
name
Name of the route, can set to default
for front-end, admin
for admin-end, home
for homepage and feed
for feed section.
params
Parameters for generating url.
options
Options for the route.
attrs
Attributes of script.
reuseMatchedParams
Whether to reuse matched parameters.
Example
$this->url('', array(
'module' => 'system',
'controller' => 'index',
'action' => 'index',
));
$this->url('home');
$this->url('default', array(
'controller' => 'index',
'action' => 'index',
));
You can also add your parameters to the second parameter of url
helper. These parameters will post by GET method, for example:
$this->url('' array(
'controller' => 'login',
'action' => 'login',
'param' => 'hello',
));
The url will be:
'path/to/www/login/login/param-hello'