<?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>Shekhar Govindarajan's Blog &#187; drupal</title>
	<atom:link href="http://www.shekhargovindarajan.com/tag/drupal/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shekhargovindarajan.com</link>
	<description>My Notepad on the Web</description>
	<lastBuildDate>Tue, 07 Feb 2012 04:58:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com/" />
			<item>
		<title>Drupal 6: Different Page Templates for different Content Types</title>
		<link>http://www.shekhargovindarajan.com/tips-n-tricks/drupal-6-different-page-templates-for-different-content-types/?&#038;owa_medium=feed&#038;owa_sid=&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=drupal-6-different-page-templates-for-different-content-types</link>
		<comments>http://www.shekhargovindarajan.com/tips-n-tricks/drupal-6-different-page-templates-for-different-content-types/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 18:00:39 +0000</pubDate>
		<dc:creator>Shekhar</dc:creator>
				<category><![CDATA[Tips N Tricks]]></category>
		<category><![CDATA[Administrator]]></category>
		<category><![CDATA[content type]]></category>
		<category><![CDATA[designer]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[drupal 6]]></category>
		<category><![CDATA[page template]]></category>
		<category><![CDATA[page.tpl.php]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.shekhargovindarajan.com/?p=1412</guid>
		<description><![CDATA[Given the flexibility of Drupal, a different page template depending on the Content Type is not very demanding. The good news is, it is very much possible. The bad news is you may have to struggle like me to find the simplest, neatest and working method to achieve it. Reading the documentation and Googling would [...]]]></description>
			<content:encoded><![CDATA[<p>Given the flexibility of Drupal, a different page template depending on the Content Type is not very demanding. The good news is, it is very much possible. The bad news is you may have to struggle like me to find the simplest, neatest and working method to achieve it.</p>
<p>Reading the documentation and Googling would result in many methods &#8211; some are confusing, some are not so neat and others apply to earlier versions of Drupal. Following is my favourite method to setup different page templates, depending on the Content Type, in Drupal 6.<span id="more-1412"></span></p>
<p><strong>What is a Page Template<br />
</strong>This is the template which contains a Node. This must not be mistaken with the node template, for example, a Story node which displays the title, teaser, images, comment form and et al. In Drupal, the default page template is written in the file named page.tpl.php (and the node template is in node.tpl.php).</p>
<p>It is the page template with which you can display three columns for certain content types and two columns for others. It is the page template using which you can dictate the column which will show a Story, a Blog entry, a Forum topic or a <a href="http://drupal.org/project/webform" target="_blank">Webform</a>. This template is where you insert the Regions for Blocks and Views.</p>
<p><strong>A Neat Solution</strong><br />
Append or write the following code in a file named template.php in your theme&#8217;s directory:</p>
<pre>&lt;?php
function &lt;theme-name&gt;_preprocess_page(&amp; $vars) {
	if (isset ($vars['node']) &amp;&amp; $vars['node']-&gt;type == "blog") {
		$vars['template_files'] = array();
		$vars['template_files'][] = 'page-blog';
	}

	if (isset ($vars['node']) &amp;&amp; $vars['node']-&gt;type == "forum") {
		$vars['template_files'] = array();
		$vars['template_files'][] = 'page-forum';
	}

	if (isset ($vars['node']) &amp;&amp; $vars['node']-&gt;type == "webform") {
		$vars['template_files'] = array();
		$vars['template_files'][] = 'page-webform';
	}
}
?&gt;
</pre>
<p>In the above code replace &lt;theme-name&gt;, in the name of the function, with the name of your Theme&#8217;s directory. For example, suppose the name of your Theme&#8217;s directory is &#8220;blue&#8221;, then:</p>
<pre>function blue_preprocess_page(&amp; $vars)</pre>
<p>Now all you need to do is what you are most creative at. Write the templates for each content type. Drop files in your theme&#8217;s directory named page-blog.tpl.php, page-forum.tpl.php and page-webform.tpl.php for the Blog entry, Form topic and Webform  respectively. Feel free to set different page layouts and Regions in these files. Note that any Content Type which is not specified in the above code will use page.tpl.php &#8211; the default page template. For example, in this case, the Story content type will use page.tpl.php.</p>
<p><strong>Important: </strong>Log into Drupal as admin and goto Administrator&gt;Site configuration&gt;Performance and click on the button &#8220;Clear cached data&#8221; (at the bottom).</p>
<p>I prefer this solution because the template selection logic goes separated into a different file, leaving the Page templates friendly for a designer. Plus, template.php is the logical place to add overrides or specific behaviour. Most likely a seasoned Drupal developer will first look into this file for customizations.</p>
<p>Created or added a new content type? All you need is to add another IF block in the above code and drop a new page template. Before concluding that it is not working for you, do remember to clear the cache.</p>
<img src="http://www.shekhargovindarajan.com/?ak_action=api_record_view&id=1412&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.shekhargovindarajan.com/tips-n-tricks/drupal-6-different-page-templates-for-different-content-types/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Drupal Views: Hide or display alternate text for 0 (zero) comments</title>
		<link>http://www.shekhargovindarajan.com/open-source/drupal-views-hide-or-display-alternate-text-for-0-zero-comments/?&#038;owa_medium=feed&#038;owa_sid=&#038;utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=drupal-views-hide-or-display-alternate-text-for-0-zero-comments</link>
		<comments>http://www.shekhargovindarajan.com/open-source/drupal-views-hide-or-display-alternate-text-for-0-zero-comments/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 14:51:34 +0000</pubDate>
		<dc:creator>Shekhar</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[author]]></category>
		<category><![CDATA[Comment]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[View]]></category>
		<category><![CDATA[views]]></category>
		<category><![CDATA[views-view-field--comment-count.tpl]]></category>

		<guid isPermaLink="false">http://www.shekhargovindarajan.com/?p=1068</guid>
		<description><![CDATA[I have been playing with Drupal Views extensively for the last three months for a Website project. Whenever I overcome a hurdle with Views, I end up realizing how powerful and flexible is the Views module. It is just me who doesn&#8217;t know all the syntax to tap it&#8217;s power. Here is one such example. [...]]]></description>
			<content:encoded><![CDATA[<p>I have been playing with Drupal <a href="http://drupal.org/project/views" target="_blank">Views</a> extensively for the last three months for a Website project. Whenever I overcome a hurdle with Views, I end up realizing how powerful and flexible is the Views module. It is just me who doesn&#8217;t know all the syntax to tap it&#8217;s power. Here is one such example. With about four lines of code, I was able to get rid of an annoyance in an otherwise neat-looking View.</p>
<p>For the Website project, I built a View to show the recent blog posts along with their title, author, post date and the number of comments. All looked fine expect the comments. It pinched me to see &#8220;0 comments&#8221;, in the View, against the posts, which did not have a comment. <span id="more-1068"></span>Ideally, the View should have  hidden the comments count or displayed an alternate text like &#8220;Write a comment&#8221;. Further, I didn&#8217;t want to theme the comment count for each individual View. This is because I had many such Views across the site. I desired a global fix to the &#8220;0 comment&#8221; case. The solution turned out to be quite simple and is as follows:</p>
<p>Save the following code in a file named views-view-field&#8211;comment-count.tpl.php in the theme&#8217;s directory -  &lt;drupal-dir&gt;/themes/&lt;your-theme&gt; . Please note the double hyphen (&#8211;) between &#8220;field&#8221; and &#8220;comment&#8221;, in the file name:</p>
<pre>&lt;?php

$zeroCommentText="0 comment(s)";

if(stristr($output,$zeroCommentText))
  $output="";

echo $output;

?&gt;
</pre>
<p>The above code assumes that you have setup the View to display the comment count as &#8220;N comment(s)&#8221;. Here N is the number of comments. Change the $zeroCommentText variable to suit your display. The above code will not display the comment count when it is zero or no comments.</p>
<p>Following is the modified code, in case, you want to display some text, say, &#8220;Write a comment&#8221; in place of &#8220;0 comment(s)&#8221;:</p>
<pre>&lt;?php

$zeroCommentText="0 comment(s)";
$replaceWith = "Write a comment";   

if(stristr($output,$zeroCommentText))
  $output = str_ireplace($zeroCommentText,$replaceWith,$output);  

echo $output;

?&gt;
</pre>
<p>Modify the $replaceWith variable, with the alternate text that you want to display for zero or no comments. Drupal Views rocks!!!</p>
<img src="http://www.shekhargovindarajan.com/?ak_action=api_record_view&id=1068&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.shekhargovindarajan.com/open-source/drupal-views-hide-or-display-alternate-text-for-0-zero-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

