<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dwight Jack Diary &#187; template override</title>
	<atom:link href="http://www.dwightjack.com/diary/tag/template-override/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dwightjack.com/diary</link>
	<description>Diary of music, design and code</description>
	<lastBuildDate>Tue, 13 Jul 2010 20:46:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using multiple templates&#8217; overrides in Joomla 1.5 modules</title>
		<link>http://www.dwightjack.com/diary/2009/09/20/multiple-templates-overrides-joomla-modules/</link>
		<comments>http://www.dwightjack.com/diary/2009/09/20/multiple-templates-overrides-joomla-modules/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 18:00:48 +0000</pubDate>
		<dc:creator>Dwight Jack</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[Joomla 1.5]]></category>
		<category><![CDATA[modules]]></category>
		<category><![CDATA[template override]]></category>

		<guid isPermaLink="false">http://www.dwightjack.com/diary/?p=227</guid>
		<description><![CDATA[Step by step tutorial on adding a custom joomla module parameter type to apply different template's overrides on a module in a per-instance style with minumum hacks.]]></description>
			<content:encoded><![CDATA[<p>One of most usefull feature in Joomla 1.5 is the ability to quickly customize the HTML output of a module by using <strong>template overrides</strong> (see <a href="http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core" target="_blank">here</a> for details).</p>
<p>The only problem is that, once you have coded an override for a module, it&#8217;ll be used for all module&#8217;s instances within the CMS. The issue here is that you might want to output one module in a column as just a simple list of links AND in the main body as a content-rich table.</p>
<p>This problem can be addressed <strong>with a module hack and the addition of a new backend parameter type</strong> (for 1.5 native modules only), both in a system wide or module specific way . Here is a step by step tutorial:</p>
<h3>Adding a new parameter to the module</h3>
<p>Joomla 1.5 features a native way to add backend parameter types beside the <a href="http://docs.joomla.org/Standard_parameter_types" target="_blank">native ones</a>. In our case i&#8217;ve realized a new element (parameter) file which will look if a template override folder exists for the spefic module and, if found, will list all PHP files whose name is prefixed with &#8220;<code>custom_</code>&#8221; . You can download the file <a href=http://www.dwightjack.com/diary/wp-content/plugins/download-monitor/download.php?id=14>here</a>.</p>
<p>Now you&#8217;ll need to place this file inside a folder called element, then open the .xml configuration file of the module and search for the <code>&lt;params&gt;</code> opening tag. Replace it with the following code (<code>YOURMODULENAME</code> is the module name):</p>
<pre><code>&lt;params addpath="/modules/mod_YOURMODULENAME/element"&gt;</code></pre>
<p>Now place the new parameter as the last child of the <code>&lt;params&gt;</code> tag:</p>
<pre><code>&lt;param name="template" type="customtemplates" modulename="mod_YOURMODULENAME" default="default" label="Custom template" description="Use this custom template file" /&gt;</code></pre>
<h3>Hacking the main PHP module file</h3>
<p>To make the module fully aware of the new template you choose, you need to pass the customtemplates paramenter to the static method which retrieves the template. For instance let&#8217;s say your <code>mod_mymodule.php</code> file has a line like this:</p>
<pre><code>require( JModuleHelper::getLayoutPath( 'mod_mymodule') );</code></pre>
<p>Now provide the <code>customtemplates</code> parameter by changing the line to:</p>
<pre><code>require( JModuleHelper::getLayoutPath( 'mod_mymodule',<span style="color: #ff0000;">$params-&gt;get('template','default')</span> ) );</code></pre>
<h3>Done!</h3>
<p>Untill no custom template&#8217;s overrides are found, the default template (default for the module or the default override if present) will be used. Once you&#8217;ll create a <code>custom_whatever.php</code> template file it&#8217;ll show up in the select list.</p>
<h3>Adding the new parameter system-wide</h3>
<p>By adding the parameter as a native-like parameter, you&#8217;ll be able to use it on all module without calling it in the &lt;params&gt; tag.</p>
<p>To add the paramenter system-wide you just have to place the <code>customtemplates.php</code> element in the /libraries/joomla/html/parameter/element folder. Since this is a custom element you shouldn&#8217;t have any problem on CMS upgrades.</p>
<h3>The drawback</h3>
<p>There&#8217;s a major drawback for this solution: since you are going to modify some module&#8217;s file you&#8217;ll need to keep a copy of them to prevent future upgrades from removing your changes (and breaking your template).</p>
<h3>Further readings</h3>
<p>Joomla has a really flexible parameter system, underused by many developers. Here are a couple of further reading to understand how parameters can help your everyday Joomla coding:</p>
<ul>
<li><a href="http://docs.joomla.org/Component_parameters#Types_of_Component_parameter" target="_blank">Joomla Docs: Component parameters</a></li>
<li><a href="http://www.teachmejoomla.net/code/joomla-1.5/joomla-php-developer-extending-config.xml-with-plugins.html" target="_blank">Joomla PHP: extending config.xml with plugins</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dwightjack.com/diary/2009/09/20/multiple-templates-overrides-joomla-modules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
