how to create right structure of the index.php file in your template

8
How to create right How to create right structure of the index.php structure of the index.php file in your template file in your template Some practical pieces of advice Some practical pieces of advice

Upload: tonytemplates

Post on 29-Aug-2014

972 views

Category:

Self Improvement


0 download

DESCRIPTION

This publication is devoted to the index.php file. We will suggest how to organize its structure.

TRANSCRIPT

Page 1: How to create right structure of the index.php file in your template

How to create right structure of the How to create right structure of the index.php file in your templateindex.php file in your template

Some practical pieces of adviceSome practical pieces of advice

Page 2: How to create right structure of the index.php file in your template

Today’s publication is devoted to the index.php file.Today’s publication is devoted to the index.php file. We will suggest how to organize its structure. We will suggest how to organize its structure.

Page 3: How to create right structure of the index.php file in your template

Index.php is a main file of your template. It contains of basic Index.php is a main file of your template. It contains of basic

HTML markup and some PHP code.HTML markup and some PHP code. Here we will try to describe main things that you have to know Here we will try to describe main things that you have to know

about how to do good foundation of your new template.about how to do good foundation of your new template. First of all you have to forbid direct access to this file:First of all you have to forbid direct access to this file:

// no direct access// no direct access defined( ‘_JEXEC’ ) or die( ‘Restricted access’ );defined( ‘_JEXEC’ ) or die( ‘Restricted access’ );

It is always good to set some variables before HTML code.It is always good to set some variables before HTML code.

Define path to your template so you could use it further:Define path to your template so you could use it further: $tpath = $this->baseurl.’/templates/’.$this->template;$tpath = $this->baseurl.’/templates/’.$this->template;

Init application object:Init application object: $app = JFactory::getApplication();$app = JFactory::getApplication();

And get template parameters:And get template parameters: $params = $app->getParams();$params = $app->getParams();

Page 4: How to create right structure of the index.php file in your template

Usually you want to include some CSS and JS files for your Usually you want to include some CSS and JS files for your template. To do this you have to initialise Document object and template. To do this you have to initialise Document object and call addStyleSheet and/or addScript methods:call addStyleSheet and/or addScript methods:

$doc = JFactory::getDocument();$doc = JFactory::getDocument(); $doc->addStyleSheet($tpath . $doc->addStyleSheet($tpath . ‘your_css_folder/your_cool_styles.css’);‘your_css_folder/your_cool_styles.css’); $doc->addScrypt($tpath . ‘your_js_folder/megascript.js’); $doc->addScrypt($tpath . ‘your_js_folder/megascript.js’);

Next we have to insert common head for HTML files with DOCTYPE Next we have to insert common head for HTML files with DOCTYPE definition:definition:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”<?php <html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”<?php echo $this->language; ?>” lang=”<?php echo $this->language; ?echo $this->language; ?>” lang=”<?php echo $this->language; ?>” >>” >

Page 5: How to create right structure of the index.php file in your template

After that we can include Joomla head content.After that we can include Joomla head content.

<head><head>

<jdoc:include type=”head” /> <jdoc:include type=”head” />

</head></head>

<jdoc:include /> <jdoc:include />

Main structure makes possible for you to show modules, component, Main structure makes possible for you to show modules, component, messages etc. on pages of your template.messages etc. on pages of your template. Inside <body> tags you can use <jdoc: include/> structure to show Inside <body> tags you can use <jdoc: include/> structure to show modules, component, messages etc. on pages of your template.modules, component, messages etc. on pages of your template.

Page 6: How to create right structure of the index.php file in your template

System messages:System messages:

<jdoc: include type=”message“/><jdoc: include type=”message“/>

Modules, for example search module:Modules, for example search module:

<jdoc:include type=”module” name=”search” /><jdoc:include type=”module” name=”search” />

Search in this case is a position in your template described in Search in this case is a position in your template described in templateDetails.xml file.templateDetails.xml file.

For modules you can also define “style” attribute.For modules you can also define “style” attribute.

<jdoc:include type=”module” name=”leftmenu” style=”xhtml”/><jdoc:include type=”module” name=”leftmenu” style=”xhtml”/>

Page 7: How to create right structure of the index.php file in your template

Style may be one of these:Style may be one of these:

xhtml – each module as separate div elementxhtml – each module as separate div element table – modules will be shown as a table with one columntable – modules will be shown as a table with one column horz - modules will be also shown as a table but horizontally horz - modules will be also shown as a table but horizontally

each module in own celleach module in own cell rounded – modules are shown in div elements with a border rounded – modules are shown in div elements with a border

and rounded cornersand rounded corners none – module content is shown without title and containernone – module content is shown without title and container

Page 8: How to create right structure of the index.php file in your template

Good coding style is to hide markup of inserting modules:Good coding style is to hide markup of inserting modules:

<?php if($this->countModules(‘search’)) : ?><?php if($this->countModules(‘search’)) : ?>

<div id=”search”><div id=”search”>

<jdoc:include type=”modules” name=”search” style=”xhtml” /><jdoc:include type=”modules” name=”search” style=”xhtml” />

</div></div>

<?php endif; ?><?php endif; ?>

And of course don’t forget to include component output:And of course don’t forget to include component output:

<jdoc:include type=”component” /><jdoc:include type=”component” />

Source of the article Source of the article