Joomla Jumpstart

  • Increase font size
  • Default font size
  • Decrease font size
Home Professional Joomla! Hacking Joomla! How To Get Joomla 1.6 Document Data within a Module

How To Get Joomla 1.6 Document Data within a Module

E-mail Print PDF
User Rating: / 11
PoorBest 

When programming a Joomla extension in PHP -- particulary when you need to create a display module -- you often need to get information about about the document being displayed. By instantiating the document object, you can get access to all of the information on everything from the metatags to the template name.

Examining the Joomla Document object

You can examine the properties available through the document object by adding these two lines to your module definition:
    

$document = &JFactory::getDocument();
print_r($document);


You will get output something like the code shown in Listing 1. So if you want to change the output of a module based on the keywords held in the metatags, you can use code like this:
    

$document = &JFactory::getDocument();
$metaTags = trim($document->_metaTags['standard']['keywords']);
$keywords = explode(',',$metaTags);

Getting information about the document can help you customize the module output to mirror the type of content displayed in the article.

Listing 1. Example of Joomla Document object information

JDocumentHTML Object
(
[_links] => Array
(
[0] => <link href="/templates/rhuk_milkyway/favicon.ico" rel="shortcut icon" type="image/x-icon"
)

[_custom] => Array
(
)

[template] => rhuk_milkyway
[baseurl] =>
[params] => JRegistry Object
(
[data:protected] => stdClass Object
(
[colorVariation] => blue
[backgroundVariation] => blue
[widthStyle] => fmax
)

)

[_file] => C:\Apache22\htdocs\joomla16\templates\rhuk_milkyway\index.php
[_template:protected] =>
[title] => Sample Sites
[description] => Joomla! - the dynamic portal engine and content management system
[link] =>
[base] => http://localhost_j16/index.php/sample-sites.html
[language] => en-gb
[direction] => ltr
[_generator] => Joomla! 1.6 - Open Source Content Management
[_mdate] =>
[_tab] =>
[_lineEnd] =>

[_charset] => utf-8
[_mime] => text/html
[_namespace] =>
[_profile] =>
[_metaTags] => Array
(
[http-equiv] => Array
(
[content-type] => text/html; charset=utf-8
)

[standard] => Array
(
[robots] => index, follow
[keywords] => joomla, Joomla
[rights] =>
[title] => Sample Sites
[author] => Super User
)

)

[_engine] =>
[_type] => html
 

Who's Online

We have 16 guests online
ilmubaru Cara menampilkan gambar dengan memakai modul Custom HTML pada Joomla (tambah module) http://t.co/2NnaZ1UV
by ilmubaru. Link: Tweet Button
joomlafrance #joomla [Problème] Installation module header accordation et slidershow: Ces deux modules ne… http://t.co/PNoo3DRZ
by joomlafrance. Link: Google
stjepantop Custom Javascript - mod_custom_js is a module for Joomla CMS. With it you can include your own content... http://t.co/8nZjUfwG
by stjepantop. Link: Tweet Old Post
stackfeed How to assign PHP Jquery in joomla Module: I dont know where to post this , so here. iam using joomla 1.7 and v... http://t.co/ONHzK1KP
by stackfeed. Link: twitterfeed

Google AdSense


Coffee and Cream Publishing