Erstellung eines einfachen Joomla! Templates
From Joomla! Documentation
It has been suggested that this article or section be split into specific version Namespaces. (Discuss). If version split is not obvious, please allow split request to remain for 1 week pending discussions. Proposed since 2 years ago.
Einleitung
Ziel dieser Anleitung ist es, eine Einführung anzubieten, wie Joomla! Vorlagen (templates) erstellt werden. Sie bietet die notwendigen Dateien und den benötigte Code um eine rudimentäre Vorlage zu erstellen. Der Code wird so angeboten, dass er kopiert und eingefügt werden kann und nur sehr wenig Veränderungen benötigt.
Einrichten einer Verzeichnisstruktur
Um die einfachste Vorlage zu erstellen, muss ein neues Verzeichnis im Verzeichnis "templates" erstellt werden. Es muss den Namen der Vorlage tragen, z.B. "meineVorlage".
Darin müssen die Dateien index.php
und templateDetails.xml
erstellt werden. Für die Organisation brauchen wir die Verzeichnisse "images" und "css" sowie im Verzeichnis "css" noch die Datei template.css
.
Obwohl es erlaubt ist Deinen CSS Code in die "index.php" zu schreiben, bevorzugen die meisten Web-Entwickler ihre CSS in eine andere Datei zu schreiben, die von vielen Seiten mit Hilfe des link
-Tags verknüpft werden kann. Das erleichtert die Pflege und verkürzt die Ladezeiten, da die Datei im Speicher gehalten werden kann (und wird).
Dies ist die einfachst mögliche Einrichtung. Gliederung der Ordner und Datei-Struktur:
* mynewtemplate/ ** css/ *** template.css ** images/ ** index.php ** templateDetails.xml
Erstellen einer grundlegenden templateDetails.xml-Datei
Die templateDetails.xml Datei ist unentbehrlich. Ohne sie kann Deine Vorlage nicht von Joomla! gesehen werden. Die Datei enthält die Schlüssel-Metadaten der Vorlage.
Die Syntax der Datei ist für jede Joomla!-Version unterschiedlich.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE install PUBLIC "-//Joomla! 1.5//DTD template 1.0//EN" "http://www.joomla.org/xml/dtd/1.5/template-install.dtd">
<install version="1.5" type="template">
<name>mynewtemplate</name>
<creationDate>2008-05-01</creationDate>
<author>John Doe</author>
<authorEmail>john@example.com</authorEmail>
<authorUrl>http://www.example.com</authorUrl>
<copyright>John Doe 2008</copyright>
<license>GNU/GPL</license>
<version>1.0.2</version>
<description>My New Template</description>
<files>
<filename>index.php</filename>
<filename>templateDetails.xml</filename>
<folder>images</folder>
<folder>css</folder>
</files>
<positions>
<position>breadcrumb</position>
<position>left</position>
<position>right</position>
<position>top</position>
<position>user1</position>
<position>user2</position>
<position>user3</position>
<position>user4</position>
<position>footer</position>
</positions>
</install>
Für und höher, benutze die folgende Version. Ändere
version="2.5"
in die Version Deiner von Joomla!-Installation.
<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="template">
<name>mynewtemplate</name>
<creationDate>2008-05-01</creationDate>
<author>John Doe</author>
<authorEmail>john@example.com</authorEmail>
<authorUrl>http://www.example.com</authorUrl>
<copyright>John Doe 2008</copyright>
<license>GNU/GPL</license>
<version>1.0.2</version>
<description>My New Template</description>
<files>
<filename>index.php</filename>
<filename>templateDetails.xml</filename>
<folder>images</folder>
<folder>css</folder>
</files>
<positions>
<position>breadcrumb</position>
<position>left</position>
<position>right</position>
<position>top</position>
<position>user1</position>
<position>user2</position>
<position>user3</position>
<position>user4</position>
<position>footer</position>
</positions>
</extension>
Wie Du sehen kannst, haben wir Informationen zwischen "Tags" (die <elemente>
). Am besten kopierst Du das in Deine templateDetails.xml-Datei und änderst die nötigen Kleinigkeiten (wie <name>
and <author>
).
Der Teil mit der <files>
sollte alle Dateien enthalten, die Du nutzt. Die kennst Du wahrscheinlich noch nicht, macht aber nichts - kannst Du später nachtragen. Das <folder>
Element wird benutzt um ein komplettes Verzeichnis (mit allen darin enthaltenen Dateien) zu definieren.
Lass die Reihenfolge, wie sie ist - dies ist eine allgemeine Zusammenstellung wodurch Du in der Lage bist, einfach von den Standard-Vorlagen zu wechseln.
Erstellen einer einfachen index.php-Datei
The index.php
file becomes the core of every page that Joomla! delivers. Essentially, you make a page (like any HTML page) but place PHP code where the content of your site should go. The template works by adding Joomla code into module positions and the component section in your template. Anything added to the template will appear on all pages unless it is added to one of these sections via the Joomla CMS (or customised code).
This page will show the bare-bones code ready for you to cut and paste into your own design.
Begin
A Joomla template begins with the following lines:
<?php defined( '_JEXEC' ) or die( 'Restricted access' );?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
The first line stops naughty people looking at your coding and getting up to bad things.
The second line is the Document Type Declaration (DOCTYPE), which tells the browser (and web crawlers) which flavor of HTML the page is using. The doctype used above is HTML5, a newer version of HTML that is largely backwards compatible, but contains many new features. You should be aware that this will not work well in Internet Explorer 8 or earlier without a hack. You might want to investigate this situation and your clients' wishes before deciding on which doctype you want to use. However this is used in Joomla and higher.
The third line begins our HTML document and describes what language the website is in. A html document is divided into two parts, head and body. The head will contain the information about the document and the body will contain the website code which controls the layout.
Head
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/system.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/system/css/general.css" type="text/css" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template; ?>/css/template.css" type="text/css" />
</head>
The first line gets Joomla to put the correct header information in. This includes the page title, meta information as well as system JavaScript.
The rest creates links to two system style sheets and to your own style sheet (if it's named template.css
and is located in the css
folder of your template directory. So if your template is in http://www.mysite.com/templates/my_template/
then the css files will go in http://www.mysite.com/templates/my_template/css/
).
Body Section
<body>
<jdoc:include type="modules" name="top" />
<jdoc:include type="component" />
<jdoc:include type="modules" name="bottom" />
</body>
Amazingly, this will suffice! Yes, it's a very basic layout, but it will do the job. Everything else will be done by Joomla!. These lines, usually called jdoc statements, tell Joomla to include output from certain parts of the Joomla system. Note: you will need to ensure your menu is set to go into the "top" module position.
Module Positions
Above, the line which says name="top"
adds a module position called top and allows Joomla to place modules into this section of the template. The type="component"
line contains all articles and main content (actually, the component) and is very important. It goes in the centre of the template.
Note: You can add your own module lines anywhere you want in the body, but you have to add a corresponding line to the templateDetails.xml file which sits alongside the index.php of your template.
End
Finish it off - one last bit:
</html>
Custom Images
If you want to add any images to the template you can do so like this:
<img src="<?php echo $this->baseurl; ?>/templates/<?php echo $this->template; ?>/images/myimage.png" alt="Custom image" class="customImage" />
Here the template variable will fill in the name of your template.
Custom CSS
You can add custom css like this:
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template;?>/css/styles.css" type="text/css" />
Every file which is added must have a line in the templateDetails.xml file for the template, unless it resides in a sub-folder (which can be included in a <folder> element).
Das ergibt zusammen die Datei:
<?php defined('_JEXEC') or die('Restricted access');?>
<!DOCTYPE html>
<html xml:lang="<?php echo $this->language; ?>" lang="<?php echo $this->language; ?>" >
<head>
<jdoc:include type="head" />
<link rel="stylesheet" href="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/css/template.css" type="text/css" />
</head>
<body>
<jdoc:include type="modules" name="top" />
<jdoc:include type="component" />
<jdoc:include type="modules" name="footer" />
</body>
</html>
Prüfen des Templates
Finde die Vorlage im Template Manager und mache es zu Deiner Standard-Vorlage.
In Joomla! 1.5 siehst Du Deine neue Vorlage sofort im Template Manager, den Du über Erweiterungen -> Template-Manager erreichst.
+ In der Joomla! 2.5 Serie und später musst Du Joomla! erst sagen, dass Du eine neue Vorlage erstellt hast. Das wird "Erweiterungen Überprüfen" genannt und kann über Erweiterungen -> Verwalten -> Überprüfen erreicht werden. Klicke auf "Überprüfen" und Joomla! entdeckt Deine Vorlage. Wähle sie aus und klicke auf "installieren". Jetzt sollte Deine Vorlage im Template Manager (Styles) über Erweiterungen -> Verwalten erreichbar sein.
Du kannst Deine Vorlage auch außerhalb der Joomla!-Installation erstellen und wie jede andere Erweiterung installieren.
HINWEIS: es gibt ein paar Wege, wie Du Deine zusammengebaute index-Seite überprüfen kannst. Platziere die Styles im Kopf der index-Seite oder verlinke die Seite mit dem Stylesheet, das Du verwendest. Du kannst diese Links löschen, bevor Du sie Seite verpackst
Die Vorlage für die Installation verpacken
A directory with several loose files is not a convenient package for distribution. So the final step is to make a package. This is a compressed archive containing the directory structure and all the files. The package can be in ZIP format (with a .zip extension), in TAR-gzip format (with a .tar.gz extension), or in TAR-bz2 format (with a .tar.bz2 extension).
If your template is in a directory mytemplate/ then to make the package you can connect to that directory and use commands like:
- tar cvvzf ../mytemplate.tar.gz *
- zip -r ..\mytemplate.zip *.*
Note to Mac OS X users
Note to template developers using Mac OS X systems: the Finder's "compress" menu item produces a usable ZIP format package, but with one catch. It stores the files in AppleDouble format, adding extra files with names beginning with "._". Thus it adds a file named "._templateDetails.xml", which Joomla 1.5.x can sometimes misinterpret. The symptom is an error message, "XML Parsing Error at 1:1. Error 4: Empty document". The workaround is to compress from the command line, and set a shell environment variable "COPYFILE_DISABLE" to "true" before using "compress" or "tar". See the AppleDouble article for more information.
To set an environment variable on a Mac, open a terminal window and type:
export COPYFILE_DISABLE=true
Then in the same terminal window, change directories into where your template files reside and issue the zip command. For instance, if your template files have been built in a folder in your personal directory called myTemplate, then you would do the following:
cd myTemplate zip -r myTemplate.zip *
Zusammenfassung
Du solltest jetzt ein funktionierendes Template erstellt haben. Es sieht noch nicht besonders aus. Das Beste, was Du jatzt tun kannst, ist mit dem Layout herumzuspielen.