Libraries: Master: Unterschied zwischen den Versionen
Tm (Diskussion | Beiträge) |
Tm (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| Zeile 9: | Zeile 9: | ||
<charset ... /> | <charset ... /> | ||
<title> ... </title> | <title> ... </title> | ||
[STATIC HEAD CONTENT (headstart)] | |||
[DYNAMIC HEAD CONTENT (headstart)] | |||
[HEAD COMPONENTS] | |||
[DYNAMIC HEAD CONTENT (headend)] | |||
[STATIC HEAD CONTENT (headend)] | |||
</head> | </head> | ||
<body> | <body> | ||
[STATIC BODY CONTENT (bodystart)] | |||
[DYNAMIC BODY CONTENT (bodystart)] | |||
[YOUR CONTROLLER OUTPUT] | [YOUR CONTROLLER OUTPUT] | ||
[DYNAMIC BODY CONTENT (bodyend)] | |||
[STATIC BODY CONTENT (bodyend)] | |||
</body> | </body> | ||
</html> | </html> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== | == Adding static content == | ||
=== Configuration | In the folder '''application/views/master/static''' you will find four files. Here you can add content to include into the master-template statically: | ||
* '''headstart.php:''' Static content at the beginning of <head>. | |||
* '''headend.php:''' Static content at the end of <head>. | |||
* '''bodystart.php:''' Static content at the beginning of <body>. | |||
* '''bodyend.php:''' Static content at the end of <body>. | |||
== Adding content by code == | |||
You can use the following function to add content to the master-template from everywhere in your code: | |||
* '''$this->master->add_headstart($content):''' Add content at the beginning of <head>. | |||
* '''$this->master->add_headend($content):''' Add content at the end of <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. | |||
* '''$this->master->add_headstart($key,$content)''' | |||
* '''$this->master->add_headend($key,$content)''' | |||
* '''$this->master->add_bodystart($key,$content)''' | |||
* '''$this->master->add_bodyend($key,$content)''' | |||
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 discarded. | |||
* '''$this->master->add_headstart($key,$content,FALSE)''' | |||
* '''$this->master->add_headend($key,$content,FALSE)''' | |||
* '''$this->master->add_bodystart($key,$content,FALSE)''' | |||
* '''$this->master->add_bodyend($key,$content,FALSE)''' | |||
== Configuration == | |||
Some basic configurations you can do here in '''application/config/master.php'''. The configuration option are: | 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. | * '''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. | ||
* '''master_static_headstart:''' Path to the view where static content will be defined for the beginning of <head>. | |||
* '''master_static_headend:''' Path to the view where static content will be defined for the end of <head>. | |||
* '''master_static_bodystart:''' Path to the view where static content will be defined for the beginning of <body>. | |||
* '''master_static_bodyend:''' Path to the view where static content will be defined for the end of <body>. | |||
* '''master_components:''' Here you can configure the master-components. Read further down a detailed description of master components. | |||
And language specific configurations can be done here in '''language/LANGUAGE/master_lang.php'''. The configuration options are: | And language specific configurations can be done here in '''language/LANGUAGE/master_lang.php'''. The configuration options are: | ||
| Zeile 30: | Zeile 74: | ||
* '''master_title:''' Set the <title> of the page. | * '''master_title:''' Set the <title> of the page. | ||
== | == Changing configuration by code === | ||
You can manipulate all configuration values dynamically from everywhere in your code by accessing the following variables: | You can read or manipulate all configuration values dynamically from everywhere in your code by accessing the following variables: | ||
* '''$this->master->config->doctype''' | * '''$this->master->config->doctype''' | ||
| Zeile 39: | Zeile 83: | ||
* '''$this->master->config->title''' | * '''$this->master->config->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: | You can of course disable the templating completely. This is important for writing Ajax-Controllers returning only json or xml. Use the following functions: | ||
| Zeile 47: | Zeile 91: | ||
* '''$this->master->is_enabled():''' Returns TRUE if master-templating is enabled. | * '''$this->master->is_enabled():''' Returns TRUE if master-templating is enabled. | ||
Alternatively you can create a file named '''.nomaster''' in the directory of the controller. The master-template will be disabled for all controllers in this directory. | |||
== Master | == 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 | 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 included before other components depends on it. | ||
By default CodeCoupler the following components are enabled: | By default CodeCoupler the following components are enabled: | ||
| Zeile 88: | Zeile 107: | ||
=== Components Configuration === | === Components Configuration === | ||
Components can be configured in '''application/config/ | Components can be configured in '''application/config/master.php'''. Every component will be described in one array with three keys: | ||
* '''enabled:''' If TRUE the component will be enabled by default. | * '''enabled:''' If TRUE the component will be enabled by default. | ||
| Zeile 102: | Zeile 121: | ||
* '''$this->master->is_component_enabled($key):''' Returns TRUE if the component is enabled, otherwise FALSE. 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 | You can find an overview of all components, their keys and how to add you own components here: [[Components: Overview]] | ||
== 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 can access the following additional variables: | 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/main.php'''. Within this template you can access the following additional variables: | ||
* '''$master_doctype | * '''$master_doctype:''' Complete <!DOCTYPE>-Tag based on the configuration "master_doctype". | ||
* '''$master_charset:''' Configuration value "master_charset". | * '''$master_charset:''' Configuration value "master_charset". | ||
* '''$master_lang:''' Configuration value "master_lang". | * '''$master_lang:''' Configuration value "master_lang". | ||
* '''$master_title:''' Configuration value "master_title". | * '''$master_title:''' Configuration value "master_title". | ||
* '''$controller_output:''' The original output of the called controller. | * '''$controller_output:''' The original output of the called controller. | ||
* '''$ | * '''$master_headstart_dynamic:''' Content for <head>, defined by enabled components and dynamically added content with "add_head()". | ||
* '''$ | * '''$master_headend_dynamic:''' Content for <head>, defined by enabled components and dynamically added content with '''add_head()'''. | ||
* '''$ | * '''$master_bodystart_dynamic:''' Content for <body> defined by dynamically added content with '''add_bodystart()'''. | ||
* '''$master_bodyend_dynamic:''' Content for <body> defined by dynamically added content with '''add_bodyend()'''. | |||
* '''$master_headstart_static:''' Content for <head>, defined by the static view '''headstart.php'''. | |||
* '''$master_headend_static:''' Content for <head>, defined by the static view '''headend.php'''. | |||
* '''$master_bodystart_static:''' Content for <body> defined by the static view '''bodystart.php'''. | |||
* '''$master_bodyend_static:''' Content for <body> defined by the static view '''bodyend.php'''. | |||
Version vom 15. Dezember 2012, 22:16 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>
[STATIC HEAD CONTENT (headstart)]
[DYNAMIC HEAD CONTENT (headstart)]
[HEAD COMPONENTS]
[DYNAMIC HEAD CONTENT (headend)]
[STATIC HEAD CONTENT (headend)]
</head>
<body>
[STATIC BODY CONTENT (bodystart)]
[DYNAMIC BODY CONTENT (bodystart)]
[YOUR CONTROLLER OUTPUT]
[DYNAMIC BODY CONTENT (bodyend)]
[STATIC BODY CONTENT (bodyend)]
</body>
</html>
Adding static content
In the folder application/views/master/static you will find four files. Here you can add content to include into the master-template statically:
- headstart.php: Static content at the beginning of <head>.
- headend.php: Static content at the end of <head>.
- bodystart.php: Static content at the beginning of <body>.
- bodyend.php: Static content at the end of <body>.
Adding content by code
You can use the following function to add content to the master-template from everywhere in your code:
- $this->master->add_headstart($content): Add content at the beginning of <head>.
- $this->master->add_headend($content): Add content at the end of <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.
- $this->master->add_headstart($key,$content)
- $this->master->add_headend($key,$content)
- $this->master->add_bodystart($key,$content)
- $this->master->add_bodyend($key,$content)
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 discarded.
- $this->master->add_headstart($key,$content,FALSE)
- $this->master->add_headend($key,$content,FALSE)
- $this->master->add_bodystart($key,$content,FALSE)
- $this->master->add_bodyend($key,$content,FALSE)
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.
- master_static_headstart: Path to the view where static content will be defined for the beginning of <head>.
- master_static_headend: Path to the view where static content will be defined for the end of <head>.
- master_static_bodystart: Path to the view where static content will be defined for the beginning of <body>.
- master_static_bodyend: Path to the view where static content will be defined for the end of <body>.
- master_components: Here you can configure the master-components. Read further down a detailed description of master components.
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.
Changing configuration by code =
You can read or manipulate all configuration values dynamically from everywhere in your code by accessing the following variables:
- $this->master->config->doctype
- $this->master->config->charset
- $this->master->config->lang
- $this->master->config->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.
Alternatively you can create a file named .nomaster in the directory of the controller. The master-template will be disabled for all controllers in this directory.
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 included 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.php. 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, their keys and how to add you own components 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/main.php. Within this template you can access the following additional variables:
- $master_doctype: Complete <!DOCTYPE>-Tag based on the configuration "master_doctype".
- $master_charset: Configuration value "master_charset".
- $master_lang: Configuration value "master_lang".
- $master_title: Configuration value "master_title".
- $controller_output: The original output of the called controller.
- $master_headstart_dynamic: Content for <head>, defined by enabled components and dynamically added content with "add_head()".
- $master_headend_dynamic: Content for <head>, defined by enabled components and dynamically added content with add_head().
- $master_bodystart_dynamic: Content for <body> defined by dynamically added content with add_bodystart().
- $master_bodyend_dynamic: Content for <body> defined by dynamically added content with add_bodyend().
- $master_headstart_static: Content for <head>, defined by the static view headstart.php.
- $master_headend_static: Content for <head>, defined by the static view headend.php.
- $master_bodystart_static: Content for <body> defined by the static view bodystart.php.
- $master_bodyend_static: Content for <body> defined by the static view bodyend.php.