Actions

Difference between revisions of "Objects, methods and properties available from your template"

From Joomla! Documentation

(adding dump of $this)
 
m (updated to 3.1)
Line 1: Line 1:
According to <nowiki><?php print_r($this); ?></nowiki> in Joomla! 1.5.9, the object '''$this''' within the index.php file of a template looks like:
+
According to <nowiki><?php print_r($this); ?></nowiki> in Joomla! 3.1, the object '''$this''' within the index.php file of the Protostar template looks like:
 
+
<source>
Object (
+
JDocumentHTML Object  
 
+
(
[_errors] => Array ( )
+
[_links] => Array
 
+
(
[title] => Article Title
+
[http://j3demo/?view=featured] => Array
 
+
(
[description] => Article Description
+
[relation] => canonical
 
+
[relType] => rel
[link] =>  
+
[attribs] => Array
 
+
(
[base] => <nowiki>http://www.example.com/page-path-and-filename </nowiki>
+
)
 
+
)
[language] => en-gb  
+
[/index.php?format=feed&type=rss] => Array
 
+
(
[direction] => ltr  
+
[relation] => alternate
 
+
[relType] => rel
[_generator] => Joomla! 1.5 - Open Source Content Management  
+
[attribs] => Array
 
+
(
[_mdate] =>  
+
[type] => application/rss+xml
 
+
[title] => RSS 2.0 )
[_tab] =>  
+
)
 
+
[/index.php?format=feed&type=atom] => Array
[_lineEnd] =>  
+
(
 
+
[relation] => alternate
[_charset] => utf-8  
+
[relType] => rel [attribs] => Array
 
+
(
[_mime] => text/html  
+
[type] => application/atom+xml
 
+
[title] => Atom 1.0
[_namespace] =>  
+
)
 
+
)
[_profile] =>  
+
[_custom] => Array
 
+
(
[_scripts] => Array (  
+
)
 
+
[template] => protostar
:[/test/media/system/js/mootools.js] => text/javascript  
+
[baseurl] =>
 
+
[params] => JRegistry Object
:[/test/media/system/js/caption.js] => text/javascript  
+
(
 
+
[data:protected] => stdClass Object
 +
(
 +
[templateColor] =>
 +
[logoFile] =>
 +
[googleFont] => 1
 +
[googleFontName] => Open+Sans
 +
[fluidContainer] => 0 )
 +
)
 +
[_file] => /home/j3demo/public_html/templates/protostar/index.php
 +
[_template:protected] =>  
 +
[_template_tags:protected] => Array
 +
(
 +
)
 +
[_caching:protected] =>
 +
[_html5:JDocumentHTML:private] =>
 +
[title] => Home
 +
[description] => Joomla 3 demo
 +
[link] => [base] => http://j3demo.org/
 +
[language] => en-gb  
 +
[direction] => ltr  
 +
[_generator] => Joomla! - Open Source Content Management  
 +
[_mdate] =>  
 +
[_tab] =>  
 +
[_lineEnd] =>  
 +
[_charset] => utf-8  
 +
[_mime] => text/html  
 +
[_namespace] =>  
 +
[_profile] =>  
 +
[_scripts] => Array  
 +
(  
 +
[/media/system/js/mootools-core.js] => Array
 +
(
 +
[mime] => text/javascript  
 +
[defer] => [async] =>
 +
)
 +
[/media/system/js/core.js] => Array
 +
(
 +
[mime] => text/javascript
 +
[defer] =>
 +
[async] =>
 +
)
 +
[/media/system/js/caption.js] => Array
 +
(
 +
[mime] => text/javascript  
 +
[defer] =>
 +
[async] =>
 +
)
 +
[/media/jui/js/jquery.min.js] => Array
 +
(
 +
[mime] => text/javascript
 +
[defer] =>
 +
[async] =>
 +
)
 +
[/media/jui/js/jquery-noconflict.js] => Array
 +
(
 +
[mime] => text/javascript
 +
[defer] =>
 +
[async] =>
 +
)
 +
[/media/jui/js/bootstrap.min.js] => Array
 +
(
 +
[mime] => text/javascript
 +
[defer] =>
 +
[async] =>
 +
)
 +
)
 +
[_script] => Array
 +
(
 +
[text/javascript] => window.addEvent('load', function() {
 +
new JCaption('img.caption');
 +
}); )
 +
[_styleSheets] => Array
 +
(
 +
[templates/protostar/css/template.css] => Array
 +
(
 +
[mime] => text/css
 +
[media] =>
 +
[attribs] => Array
 +
(
 +
)
 +
)
 +
)
 +
[_style] => Array
 +
(
 +
)
 +
[_metaTags] => Array
 +
(
 +
[http-equiv] => Array
 +
(
 +
[content-type] => text/html; charset=utf-8
 +
)
 +
[standard] => Array
 +
(
 +
[keywords] =>
 +
[rights] =>
 +
)
 +
)
 +
[_engine] =>
 +
[_type] => html
 +
[_errors:protected] => Array
 +
        (
 +
        )
 
)  
 
)  
 
+
</source>
[_script] => Array ( )
+
 
+
[_styleSheets] => Array ( )
+
 
+
[_style] => Array ( )
+
 
+
[_metaTags] => Array (
+
 
+
:[http-equiv] => Array (
+
 
+
::[content-type] => text/html; charset=utf-8
+
:)
+
 
+
:[standard] => Array (
+
 
+
::[robots] => index, follow
+
 
+
::[keywords] => page,keywords
+
 
+
::[title] => Article Title
+
 
+
::[author] => Article Author
+
 
+
:)
+
 
+
)
+
 
+
[_engine] =>
+
 
+
[_type] => html
+
 
+
[_buffer] => Array (
+
:[component] => Array (
+
::[] =>
+
::HTML page content
+
:)
+
)
+
 
+
[_links] => Array ( )
+
 
+
[_custom] => Array ( )
+
 
+
[template] => template_name
+
 
+
[baseurl] => /
+
 
+
[params] => Array (
+
:[template] => template_name
+
:[file] => this_filename.php
+
:[directory] => /full/system/path/to/this/template
+
)
+
 
+
[_file] => /full/system/path/to/this_filename.php
+
 
+
)
+
  
  
== Examples ==
+
=== Example of using objects===
 
<link rel="stylesheet" href="'''<?=$this->baseurl ?>'''/templates/'''<?=$this->template ?>'''/css/template_css.css" type="text/css"/>
 
<link rel="stylesheet" href="'''<?=$this->baseurl ?>'''/templates/'''<?=$this->template ?>'''/css/template_css.css" type="text/css"/>

Revision as of 08:55, 23 June 2013

According to <?php print_r($this); ?> in Joomla! 3.1, the object $this within the index.php file of the Protostar template looks like:

JDocumentHTML Object 
(
         [_links] => Array 
                (
                         [http://j3demo/?view=featured] => Array
                                 (
                                        [relation] => canonical
                                        [relType] => rel 
                                        [attribs] => Array 
                                                (
                                                 )
                                 )
                         [/index.php?format=feed&type=rss] => Array 
                                (
                                        [relation] => alternate 
                                        [relType] => rel 
                                        [attribs] => Array 
                                                ( 
                                                        [type] => application/rss+xml 
                                                        [title] => RSS 2.0 )
                                                 )
                                         [/index.php?format=feed&type=atom] => Array 
                                                ( 
                                                        [relation] => alternate 
                                                        [relType] => rel [attribs] => Array 
                                                                ( 
                                                                        [type] => application/atom+xml 
                                                                        [title] => Atom 1.0
                                                                 ) 
                                                 ) 
        [_custom] => Array 
                (
                 ) 
        [template] => protostar 
        [baseurl] => 
        [params] => JRegistry Object 
                ( 
                        [data:protected] => stdClass Object 
                                ( 
                                        [templateColor] => 
                                        [logoFile] => 
                                        [googleFont] => 1 
                                        [googleFontName] => Open+Sans 
                                        [fluidContainer] => 0 ) 
                                ) 
        [_file] => /home/j3demo/public_html/templates/protostar/index.php 
        [_template:protected] => 
        [_template_tags:protected] => Array 
                ( 
                ) 
        [_caching:protected] => 
        [_html5:JDocumentHTML:private] => 
        [title] => Home 
        [description] => Joomla 3 demo 
        [link] => [base] => http://j3demo.org/ 
        [language] => en-gb 
        [direction] => ltr 
        [_generator] => Joomla! - Open Source Content Management 
        [_mdate] => 
        [_tab] => 
        [_lineEnd] => 
        [_charset] => utf-8 
        [_mime] => text/html 
        [_namespace] => 
        [_profile] => 
        [_scripts] => Array 
                ( 
                        [/media/system/js/mootools-core.js] => Array 
                                ( 
                                        [mime] => text/javascript 
                                        [defer] => [async] => 
                                ) 
                        [/media/system/js/core.js] => Array 
                                ( 
                                        [mime] => text/javascript 
                                        [defer] => 
                                        [async] => 
                                )       
                        [/media/system/js/caption.js] => Array 
                                ( 
                                        [mime] => text/javascript 
                                        [defer] => 
                                        [async] => 
                                ) 
                        [/media/jui/js/jquery.min.js] => Array 
                                ( 
                                        [mime] => text/javascript 
                                        [defer] => 
                                        [async] => 
                                ) 
                        [/media/jui/js/jquery-noconflict.js] => Array 
                                ( 
                                        [mime] => text/javascript 
                                        [defer] => 
                                        [async] => 
                                ) 
                        [/media/jui/js/bootstrap.min.js] => Array 
                                ( 
                                        [mime] => text/javascript 
                                        [defer] => 
                                        [async] => 
                                ) 
                ) 
        [_script] => Array 
                ( 
                        [text/javascript] => window.addEvent('load', function() { 
                                new JCaption('img.caption'); 
                        }); ) 
        [_styleSheets] => Array 
                ( 
                        [templates/protostar/css/template.css] => Array 
                                ( 
                                        [mime] => text/css 
                                        [media] => 
                                        [attribs] => Array 
                                                ( 
                                                ) 
                                ) 
                ) 
        [_style] => Array 
                ( 
                ) 
        [_metaTags] => Array 
                ( 
                        [http-equiv] => Array 
                                ( 
                                        [content-type] => text/html; charset=utf-8 
                                ) 
                        [standard] => Array 
                                ( 
                                        [keywords] => 
                                        [rights] => 
                                ) 
                ) 
        [_engine] => 
        [_type] => html 
        [_errors:protected] => Array
                        (
                        )
)


Example of using objects

<link rel="stylesheet" href="<?=$this->baseurl ?>/templates/<?=$this->template ?>/css/template_css.css" type="text/css"/>