Libraries: Master: Unterschied zwischen den Versionen
Tm (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Tm (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| Zeile 106: | Zeile 106: | ||
== Extended Usage == | == Extended Usage == | ||
In some cases maybe you have to modify the basic structure of the master template. Or you want to define what else then a html-documnet. In this case you can modify the file '''application/views/master/main.php'''. Within this template you van access all configuration values like a standard php-variable ($master_doctype, $master_lang etc.). Beyond this you have the following additional variables: | |||
* '''$ | * '''$controller_output:''' The original output of the called controller. | ||
* '''$master_head:''' Content for <head>, defined by enabled components and dynamically added content with "add_head()". | |||
* '''$master_bodystart:''' Content for <body> defined by dynamically added content with "add_bodystart()". | |||
* '''$master_bodyend:''' Content for <body> defined by dynamically added content with "add_bodyend()". | |||
Version vom 25. August 2012, 01:17 Uhr
In contrast to the basic CodeIgniter framework, every output of a controller will be surrounded by a master-template. All the handling will be driven by the library "Master" (accesible via $this->master). This library will be autoloaded.
The basic layout of the master template looks like this:
<!DOCTYPE ... />
<html ... >
<head>
<charset ... />
<title> ... </title>
</head>
<body>
[YOUR CONTROLLER OUTPUT]
</body>
</html>
Basics
Configuration
Some basic configurations you can do here in application/config/master.php. The configuration option are:
- master_doctype: Defines the HTML-Documenttype. Can be one of the following: xhtml11, xhtml1-strict, xhtml1-trans, xhtml1-frame, html5, html4-strict, html4-trans, and html4-frame. Values are saved in the doctypes config file. Attention! You should leave the doctype to “xhtml1-strict”. The most jQuery addons works only perfectly in this mode.
And language specific configurations can be done here in language/LANGUAGE/master_lang.php. The configuration options are:
- master_charset: Set charset of the page.
- master_lang: Set the attrinbute "lang" of <html>.
- master_title: Set the <title> of the page.
Dynamically Configuration
You can manipulate all configuration values dynamically from everywhere in your code by accessing the following array:
- $this->master->config['master_doctype']
- $this->master->config['master_charset']
- $this->master->config['master_lang']
- $this->master->config['master_title']
Enable or Disable Completely
You can of course disable the templating completely. This is important for writing Ajax-Controllers returning only json or xml. Use the following functions:
- $this->master->disable(): Disable the master-templating.
- $this->master->enable(): Enable the master-templating.
- $this->master->is_enabled(): Returns TRUE if master-templating is enabled.
Extending Master
Statically
You can add own static content into the master template. In the folder application/views/master you will find the following files:
- head.php: Static content for the <head>.
- bodystart.php: Static content at the beginning of <body>.
- bodyend.php: Static content at the end of <body>.
Dynamically
You can use the following function to add content to the master-template from everywhere in your code:
- $this->master->add_head($content): Add content into the <head>.
- $this->master->add_bodystart($content): Add content at the beginning of <body>.
- $this->master->add_bodyend($content): Add content at the end of <body>.
Or more sophisticated by specifying a key. If somewhere have been added content with the same key, the previous content will be overwritten. Alternatively you can specify one more parameter "overwrite". Setting "overwrite" to FALSE the previous content will not be overwritten, it will be retained and your content will descarded.
- $this->master->add_head($key,$content): Add content into the <head>.
- $this->master->add_head($key,$content,$overwrite): Add content into the <head>.
- $this->master->add_bodystart($key,$content): Add content at the beginning of <body>.
- $this->master->add_bodystart($key,$content,$overwrite): Add content at the beginning of <body>.
- $this->master->add_bodyend($key,$content): Add content at the end of <body>.
- $this->master->add_bodyend($key,$content,$overwrite): Add content at the end of <body>.
Master Components
Components are sets of content for the <head> that can be enabled or disabled by config or by code. Components can depend on each other. Enabling one component will enable all depending components, too. Disabling a component, will disable all other depending components, if not used otherwise. Components will always be include before other components depends on it.
By default CodeCoupler the following components are enabled:
- jQuery
- jQuery-UI
- IE9.js
- html5shiv
- yaml
Components Configuration
Components can be configured in application/config/master_components. Every component will be described in one array with three keys:
- enabled: If TRUE the component will be enabled by default.
- config: This value ist component specific. Please read the chapter Components: Overview.
- depends: Thia array tells the framework on what components this one depends. Normally you do not have to modify this.
Enable/Disable Components Dynamicaly
Everywhere in your code you can enable or disable components. You do not have to worry about enabling depending components or the order of the components. Use the following function to handle components:
- $this->master->enable_component($key): Enable component. Use the key of the component.
- $this->master->disable_component($key): Enable component. Use the key of the component.
- $this->master->is_component_enabled($key): Returns TRUE if the component is enabled, otherwise FALSE. Use the key of the component.
You can find an overview of all components and their keys here: Components: Overview
Extended Usage
In some cases maybe you have to modify the basic structure of the master template. Or you want to define what else then a html-documnet. In this case you can modify the file application/views/master/main.php. Within this template you van access all configuration values like a standard php-variable ($master_doctype, $master_lang etc.). Beyond this you have the following additional variables:
- $controller_output: The original output of the called controller.
- $master_head: Content for <head>, defined by enabled components and dynamically added content with "add_head()".
- $master_bodystart: Content for <body> defined by dynamically added content with "add_bodystart()".
- $master_bodyend: Content for <body> defined by dynamically added content with "add_bodyend()".