- Details
- Category: Joomla
http://www.webfinitytc.com/blog/how-to-convert-static-html-to-joomla-3-template/
Joomla! 3 is slightly different from Joomla! 2.5, with some minor changes and improvements in how it calls template files and template modules and components. Here is a very simplified, minimalist guide on how to convert a static HTML website to a dynamic, Joomla! 3 template and website.
1 - Create templateDetails.xml File
First, just like Joomla! 2.5, you must create a templateDetails.xml file. You must use this file to register all of the files and directories that will be used for your Joomla template. You can learn more about the templateDetails.xml file here.
2 - Create index.php File
Let's assume that your static HTML file looks something like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<link rel="stylesheet" href="css/main.css">
<script src=""></script>
<script src=""></script>
</head>
<body>
<nav>
<ul>
<li><a href="/index.html">Home</a></li>
<li><a href="/about.html">About Us</a></li>
<li><a href="/contact.html">Contact Us</a></li>
</ul>
</nav>
<div class="small-8 column">
<main>
<h1>Home Page Title</h1>
<p>Home page content goes here.</p>
</main>
</div>
<div id="sidebar" class="small-4 column">
<p>Some sidebar text goes here</p>
</div>
<footer>
<p>This Joomla! template was made with love.</p>
</footer>
</body>
</html>
Now let's take that HTML template and make it a PHP template. PHP is a server-side scripting language used to output HTML, which the web browser then renders. Joomla! is built with PHP, so to create a Joomla! template, we'll use PHP as well. So let's copy and paste the contents of your static HTML file (which should be called something like 'index.html') into a new file called index.php. Now let's make some changes - notice how the componenets from the head of the document are now before the head in the PHP section. By doing this, we're registering those resources to be in the head of the document with Joomla!, then calling them into the head with <jdoc:include type="head" />
<?php
defined('_JEXEC') or die;
$doc = JFactory::getDocument();
/* Let's tell Joomla! to use HTML5 */
$doc->setHtml5(true);
/* Now let's add any stylesheets and/or javascripts that our theme will use */
$doc->addStyleSheet($this->baseurl . '/templates/' . $this->template . '/css/main.css');
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/main.js');
$doc->addScript($this->baseurl . '/templates/' . $this->template . '/js/jquery.min.js');
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<jdoc:include type="head" />
</head>
<body>
<nav>
<ul>
<li><a href="/index.html">Home</a></li>
<li><a href="/about.html">About Us</a></li>
<li><a href="/contact.html">Contact Us</a></li>
</ul>
</nav>
<div class="small-8 column">
<main>
<h1>Home Page Title</h1>
<p>Home page content goes here.</p>
</main>
</div>
<div id="sidebar" class="small-4 column">
<p>Some sidebar text goes here</p>
</div>
<footer>
<p>This Joomla! template was made with love.</p>
</footer>
</body>
</html>
Anytime you use a resource in your theme such as an image or a file of any kind, you should use a dynamic path. So when you add an image to your template, it should look something like this:
<img src="/<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/img/someImage.png">
Notice the snippets of php mixed in with the image path above - using php will keep the theme working correctly, even if the domain name is changed or if a future Joomla! update changes the directory structure.
3 - Determine Your Content Types
You must go through each page of your static website and determine which parts of your current site will be Articles and which parts will be Modules. Obviously, the main feature parts of each page will be your articles.
4 - Add Your Content to Joomla! 3
Login to your Joomla! 3 installation and add the content from your static website to the appropriate Modules or Articles. When adding a module, the module type should be of type Custom HTML.
5 - Replace Content with Module or Article Call
Now, to replace your content with a module position, we will use the following steps:
Your module contents should look like the following(ish) before changes:
<div class="this-container">
<h3>This is a module</h3>
<p>These are my module contents</p>
</div>
Your module should then be changed to look like this:
<?php if($this->countModules('this-container')) : ?>
<div class="this-container">
<jdoc:include type="modules" name="this-container" style="xhtml" />
</div><!-- /.this-container -->
<?php endif ;?>
Where This is a module would be the Module Title in Joomla! and These are my module contents would be the CustomOutput of the Module.
- Notice, we simply wrapped the original
divin a PHP statement, and put the contents of thedivin our Joomla! 3 module in the admin side of our Joomla! 3 installation. The contents were replaced with the module call<jdoc:include...
To replace your article content with an Article Position, we will use the following steps:
Your article contents should look like the following(ish) before changes:
<div class="main-content">
<h1>Article Title</h1>
<p>Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents. Article contents.</p>
</div>
Your article contents should then be changed to look like this:
<div class="main-content">
<jdoc:include type="message" />
<jdoc:include type="component" />
</div>
Where Article Title would be the Article Title in Joomla! and Article contents... would be the contents of the article in Joomla!
- Note - do not add the php if statement for the main-content call. Also, the main content div should be called in the templateDetails.xml file.
6 - Install Your Template to Joomla! 3
Finally, the rewarding part. Zip your template directory and upload the .zip file to the extension manager in Joomla! 3. Go into your modules and select their appropriate module positions based on your specific template. You''re done!
- Note - There''s a chance, depneding on your code, that you''ll have to make significant updates to your HTML/CSS for your template to appear correctly. This generally happens because of how it calls its objects. Use the Firebug plugin on Firefox if you need help troubleshooting appearance issues.