官术网_书友最值得收藏!

Understanding jdoc statements

Any Joomla! template will need to insert content managed by Joomla! into your website. This is done with the jdoc statements in the Joomla! template.

Getting ready

Open the index.php file of the rhuk_milkyway template, which is located in the templates\rhuk_milkyway directory of your Joomla! installation.

How to do it...

Each "block" of content within Joomla! is inserted with a different jdoc statement within the index.php file. There are four fundamental statements that we'll look at:

  • Component jdoc statements
  • Head jdoc statements
  • Module and modules statements

Component jdoc statements

Component jdoc statements insert the main content for the current component into your Joomla! template. You can insert the primary page content for a particular page in Joomla! with this jdoc statement, within the<body> element of your page:

<jdoc:include type="component" />

Simple! This statement ensures that any page title and content associated with the page is inserted into your template.

Head jdoc statements

The head jdoc statement inserts relevant code into the<head> element of your page. This includes:

  • The current page's title
  • The current page's metadata; in particular, the keywords and description fields for the page
  • The robots metadata field that tells search engines whether they should take notice of the current page or not
  • Links to your template's favicon (the icon that appears near the address bar in your browser)
  • Links to alternate feeds for your content (that is, RSS and Atom feeds)
    <jdoc:include type="head" />
    

Typically, this produces code similar to the following code snippet in your template:

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="robots" content="index, follow" />
<meta name="keywords" content="joomla, Joomla" />
<meta name="description" content="Joomla! - the dynamic portal engine and content management system" />
<meta name="generator" content="Joomla! 1.5 - Open Source Content Management" />
<title>Welcome to the Frontpage</title> 
<link href="/joomla/index.php?format=feed&amp;type=rss" rel="alternate" type="application/rss+xml" title="RSS 2.0" />
<link href="/joomla/index.php?format=feed&amp;type=atom" rel="alternate" type="application/atom+xml" title="Atom 1.0" />
<!—some code omitted -->
</head>

How it works...

When Joomla! loads a page, it uses the index.php file to generate the page that is displayed. The jdoc statements tell Joomla! where in the (X)HTML document content is required.

There's more...

There are quite a few different types of jdoc statements available to Joomla! templates that aren't used very frequently.

Installation jdoc statement

The installation jdoc statement is used only in Joomla!'s installer template, so it is not of much use to the frontend Joomla! templates:

<jdoc:include type="installation" />

Message jdoc statement

The message jdoc statement inserts any system messages or error messages that Joomla! needs to display:

<jdoc:include type="message" />

It may be worth surrounding this in a<div> tag made collapsible by using JavaScript so that your visitors can close the message once it has been read.

jdoc statements and the style attribute

If you have looked at other Joomla! template files, you may have come across jdoc statements similar to this one:

<jdoc:include type="modules" name="top" style="xhtml" />

The style attribute refers to the module chrome so that if no value for this attribute is given, the attribute takes a default value of None (that is, no additional styling is provided).

Note

You can use the style attribute on module and modules-type jdoc statements, but not components. As a general rule, xhtml or no value is fine for most purposes in your Joomla! template. More information on the style attribute is available from Joomla!'s documentation at http://docs.joomla.org/What_is_module_chrome?.

See also

  • Understanding the templateDetails.xml file
  • Understanding Joomla! template positions
  • Styling Joomla! error messages
主站蜘蛛池模板: 峨边| 六安市| 南平市| 新干县| 新宾| 武定县| 宁国市| 永靖县| 呼玛县| 应城市| 教育| 阿巴嘎旗| 平和县| 靖西县| 呼图壁县| 佳木斯市| 兰溪市| 宜城市| 安陆市| 韶关市| 钦州市| 宜州市| 巫溪县| 罗田县| 汉川市| 昌乐县| 正阳县| 清新县| 沅江市| 铜鼓县| 南汇区| 项城市| 金溪县| 灵山县| 潜山县| 凌源市| 子长县| 万源市| 诸暨市| 克拉玛依市| 尉犁县|