<?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>The Open Sourcerer &#187; yvBBCode</title>
	<atom:link href="http://www.theopensourcerer.com/tag/yvbbcode/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.theopensourcerer.com</link>
	<description>The Magic of Open Source</description>
	<lastBuildDate>Tue, 24 Jan 2012 09:10:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Joomla! Hacking: Menus, Modules, Articles and Rings</title>
		<link>http://www.theopensourcerer.com/2009/01/22/joomla-hacking-menus-modules-articles-and-rings/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=joomla-hacking-menus-modules-articles-and-rings</link>
		<comments>http://www.theopensourcerer.com/2009/01/22/joomla-hacking-menus-modules-articles-and-rings/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 18:01:52 +0000</pubDate>
		<dc:creator>Alan Lord</dc:creator>
				<category><![CDATA[Runes and tales]]></category>
		<category><![CDATA[The Open Learning Centre]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[ion design it]]></category>
		<category><![CDATA[Joomla!]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Web Developer]]></category>
		<category><![CDATA[yvBBCode]]></category>

		<guid isPermaLink="false">http://www.theopensourcerer.com/?p=673</guid>
		<description><![CDATA[I wanted to share a little Joomla! hacking I did the other day for two reasons: Because I think what I managed to do was pretty damn cool (someone else might think otherwise of course), Because I think there must be a better, less intrusive, way to do what I wanted. So I am hoping [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to share a little Joomla! hacking I did the other day for two reasons:</p>
<ol>
<li>Because I <em>think</em> what I managed to do was pretty damn cool (someone else might think otherwise of course),</li>
<li>Because I think there must be a better, less intrusive, way to do what I wanted. So I am hoping for some comments from hardcore Joomla! guys.</li>
</ol>
<p>So, the scenario is this: A good customer of ours, <a href="http://iondesignit.com/" target="_blank">ion design it</a> a web design firm, asked me to build them a template, from scratch, for a particular client of theirs. This is something I&#8217;ve done before and will probably do again (basically, in this role, I help the artists with a fantastic eye for design make their artwork <em>work</em> in Joomla!). Clive, my customer, does come up with some cracking designs&#8230; Follow some of the links from his home page if you&#8217;re interested.</p>
<p>After being given the job, I started looking through the 5 page PDF which he submitted with the design. One page had a rather troubling menu layout&#8230;</p>
<div id="attachment_674" class="wp-caption alignnone" style="width: 310px"><a href="http://www.theopensourcerer.com/wp-content/uploads/2009/01/joomla-1.png"><img class="size-medium wp-image-674" title="Joomla! Menu in-the-round" src="http://www.theopensourcerer.com/wp-content/uploads/2009/01/joomla-1-300x168.png" alt="Joomla! Menu in-the-round" width="300" height="168" /></a><p class="wp-caption-text">Joomla! Menu in-the-round</p></div>
<p>After quite a bit of head scratching, this is actually what I have managed to achieve. The image is taken straight from Firefox 3 running on Ubuntu 8.10. That is Joomla! 1.5.9, the blue boxes arranged in an elipse are actually real Joomla! menu items! At this stage, the template is still being developed and doesn&#8217;t have the proper graphics but the basic physical layout and structure is there.</p>
<p>Each dark blue box <em>in-the-round</em> is a regular menu item in Joomla! that is a sub-menu of the menu shown along the top. Using the new split-menu technique in Joomla! 1.5 I am able to use seperate <em>menu modules</em> to display different layers of a single menu heirarchy, so that I can retain the &#8220;active&#8221; highlighting in the main menu for example.</p>
<p>Making the menu items appear in this ring arrangement isn&#8217;t really too hard; I just used absolute positioning of the <code>&lt;li&gt;</code> elements. Each menu item has a unique class such as <code>&lt;li class="item62"&gt;</code>. <em>It even mostly works in IE6!</em></p>
<p><strong>However, there is a much bigger issue</strong>&#8230; On other pages of the site, the same sub-menu content needs to be displayed but with a different, more traditional, layout; as here:</p>
<div id="attachment_675" class="wp-caption alignnone" style="width: 310px"><a href="http://www.theopensourcerer.com/wp-content/uploads/2009/01/joomla-2.png"><img class="size-medium wp-image-675" title="Regular Vertical Menu in Joomla!" src="http://www.theopensourcerer.com/wp-content/uploads/2009/01/joomla-2-300x175.png" alt="Regular Vertical Menu in Joomla!" width="300" height="175" /></a><p class="wp-caption-text">Regular Vertical Menu in Joomla!</p></div>
<p>To achive this I realised there were several problems to overcome:</p>
<ul>
<li>The titles in the sub-menu needed to break across several lines so they wrapped consistently,</li>
<li>the menu module responsible for displaying the menu had to be the same for both layouts or I would lose the active highlighting of the top menu,</li>
<li>I wanted to have a single menu so it was easy for my customer or their end-user to modify and update the site,</li>
<li>the ring menu really needed to be text based so it was properly indexable and accessible,</li>
<li>Joomla! only allows custom CSS class or id tags to be added at the module level and not at the article level.</li>
</ul>
<p>To fix the first problem, having line breaks (or <code>&lt;br /&gt;</code> elements) in menu items, I used an excellent plugin called <a title="yvBBCode Joomla! Plugin" href="http://yurivolkov.com/Joomla/yvBBCode/index_en.html" target="_blank">yvBBCode</a>. It enables you to insert BB Codes, such as <code>[br]</code> for example, anywhere in Joomla! Including in menu titles. The plugin then converts these BB codes to XHTML codes on the fly.</p>
<p>In the end, the solution for the menu layout itself was fairly straightforward, but required a minor hack to the Joomla! core (you can&#8217;t use the override facility here) and a small eval script on the template&#8217;s <code>index.php</code> page.</p>
<p>I added a custom <del datetime="2009-01-22T20:08:22+00:00">radio</del> list parameter (<code>ring_menu</code>) to the article.xml file in <code>administrator/components/com_content/models/article.xml</code>:</p>
<p><code>	&lt;params group="advanced"&gt;<br />
	    &lt;!-- Added by Alan Lord. 22/01/09 --&gt;<br />
      	&lt;param name="ring_menu" type="list" default="vertical" label="Menu Style" description="Chose a normal or ring style menu layout"&gt;<br />
            &lt;option value="vertical"&gt;Vertical&lt;/option&gt;<br />
            &lt;option value="ring_menu"&gt;Ring Menu&lt;/option&gt;<br />
        &lt;/param&gt;<br />
        &lt;!-- End modification --&gt;</code></p>
<p>On the particular article where I wanted the menu displayed &#8220;in-the-round&#8221; I set this <del datetime="2009-01-22T20:08:22+00:00">radio</del> list param to &#8220;Ring Menu&#8221;. The option is shown in the Article Advanced Parameters accordion <em>(the default setting is &#8220;vertical&#8221; BTW)</em>. You can see how the custom parameter is displayed here. Note the first item in the <em>Parameters (Advanced)</em> menu on this screenshot.</p>
<div id="attachment_725" class="wp-caption alignnone" style="width: 310px"><a href="http://www.theopensourcerer.com/wp-content/uploads/2009/01/joomla-3.png"><img src="http://www.theopensourcerer.com/wp-content/uploads/2009/01/joomla-3-300x248.png" alt="Custom Article Parameter" title="Custom Article Parameter" width="300" height="248" class="size-medium wp-image-725" /></a><p class="wp-caption-text">Custom Article Parameter</p></div>
<p>Now we have a parameter to play with, in the template&#8217;s <code>index.php</code> file in the <code>&lt;head&gt;</code> area, I can read this value into a php variable (<code>$class</code>). </p>
<p><code>        // This loads a custom article parameter "Ring Menu". The custom parameter is defined in<br />
        // administrator/components/com_content/models/article.xml. It defaults to Vertical, the other<br />
        // option currently is "Ring Menu".<br />
        // We can read this parameter and apply a different style to a module based on the page<br />
        $params = &amp;JComponentHelper::getParams( 'com_content' );<br />
        $class = $params-&gt;get('ring_menu');</code></p>
<p>Further down the script, where the menu module itself is loaded, the <code>$class</code> variable is echoed into the surrounding div. Thus, when the particular article in question is loaded, the container div for the menu changes from <code>&lt;div id="sub-menu" class="vertical"&gt;</code> to <code>&lt;div id="sub-menu" class="ring-menu"&gt;</code>. So my stylesheet can now do its magic and render the sub-menu, or any module for that matter, in the manner which I choose.</p>
<p>I hope this is useful to some and I would really love to know if there is a way to achieve the same result (i.e. adding a style class based on the article being viewed) without needing to hack the Joomla! core. I&#8217;m sure there probably is&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.theopensourcerer.com/2009/01/22/joomla-hacking-menus-modules-articles-and-rings/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

