Wiki : PageVariables
Documentation Home :: Categories :: Index :: Recent Changes :: Comments :: Search :: Help :: Login/RegisterPage variables
Page variables can be used to add information to the <head>-section of a web page. This can be done either in the program code (either a module or a block) or in a template.
PostNuke takes care that each value is only used once in the output. So if two or three load the same javascript file it will appear only once in the rendered page.
Examples:
- add a stylesheet file from a module when using a block while the corresponding module is not used (eg. load a forum stylesheet in the forums statisticsblock while browsing some Pagesetter publications).
- add an external javascript file in a template
- set a page title
- add meta keywords
- add parameters to the <body>-tag
Basics
There are two different types of page vars:
- single value vars (eg. title)
- multi value vars (eg. stylesheet, javascript)
The page vars are automatically added to the page output by pnTheme? class when rendering a Xanthia theme. Javascript and stylesheets are embraced by a comment:
<!-- pagevars --> ... <!-- /pagevars -->
Preperations
Before they can be used they have to be initialized with PageUtil::registerVar∞. During the pnInit? process this is automatically been done for
- title (single)
- stylesheet (multi)
- javascript (multi)
- keywords (multi)
- body (multi)
- rawtext (multi)
API functions
- PageUtil::addVar∞ for adding a value to a multi value page var
- PageUtil::getVar∞ returns the page var(s), result will be an array for multi value vars, otherwise a string
- PageUtil::registerVar∞ registers a new page var, can define a default value if needed
- PageUtil::resetVar∞ reset a pa ge var to the default if defined
- PageUtil::setVar∞ to set a single value page var
Template usage
Use
<!--[pnpageaddvar name="javascript" value="path/to/myscript.js"]-->
in your templatecode to insert a page variable directly from a template.
title
Type: single value
Defines the page title as shown in the browsers title bar. When called multiple times the last value wins.
PageUtil::setVar('title', 'PostNuke .8 support page');
displays 'PostNuke .8 support page' in the browser title:
<title>PostNuke .8 support page</title>
stylesheet
Type: multi value
Adds a stylesheet file:
PageUtil::addVar('stylesheet', 'modules/mymodule/pnstyle/style.css');
Filename must include path.
Ouput:
javascript
Type: multi value
Adds a javascript file:
PageUtil::addVar('javascript', 'modules/mymodule/pnjavascript/script.js');
Filename must include path.
Output:
keywords
Type: multi value
Adds a keyword to the list of keywords included in the meta/keywords header tag:
PageUtil::addVar('keyword', 'support');
The keywords will only be displayed if dynamic keywords are enabled in the SettingsAdmin.
body
Type: multi value
Adds a parameter for the <body>-tag
PageUtil::addVar('body', 'onload="init();"');
Output:
<body onload="init();">
rawtext
Rawtext: multi value
Adds a generic text to the header of the page
PageUtil::addVar('rawtext', 'GenericText');
Output:
GenericText
