<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://oif.eafarris.com" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
 <title>planet drupal</title>
 <link>http://oif.eafarris.com/tags/planet-drupal</link>
 <description>The taxonomy view with a depth of 0.</description>
 <language>en</language>
<item>
 <title>Review: Drupal 5 Themes</title>
 <link>http://oif.eafarris.com/content/review-drupal-5-themes</link>
 <description>&lt;p&gt;&lt;a href=&quot;/freelinking/Drupal&quot; class=&quot;freelinking&quot;&gt;Drupal&lt;/a&gt; has seen a number of books written about it in the last 18 months or so, the sign of a healthy platform. The latest of these books is &lt;strong&gt;Drupal 5 Themes&lt;/strong&gt;, by Ric Shreves, published by Packt Publishing. The book covers the process of making a Drupal site look how you want it, known as theming. Theming Drupal is a multi-step process, due to the flexibility and customizability of Drupal itself. This book serves as a fine introduction to the process and methods of Drupal theming; however, it is not without its rough patches.
&lt;!--break--&gt;&lt;/p&gt;

&lt;p&gt;The book is lean, right around 250 pages, and even that is including a completely superfluous appendix, and some other sections that could have easily be kept out without too much loss of content. Starting out with the obligatory and well done introduction section, we quickly move right in to customizing the themes that come with Drupal, and how to install a contributed theme. While we could have done without the hand-holding as we look at the basic parts of theme configuration, it is a fine introduction to the amount of configuration possible without delving into theming itself. The author takes us through a fictional client&amp;#8217;s requirements for a site, and shows how those design elements would be implemented in Drupal, without writing any code.&lt;/p&gt;

&lt;p&gt;A brief discussion of the various theming engines that are available is suitably brief enough, as Drupal theming today revolves around PHPTemplate, and, soon, it&amp;#8217;s time to start delving into Drupal&amp;#8217;s custom templating language. PHPTemplate was written specially for Drupal, and it deftly balances flexibility and power, as it remains easy for developers and designers alike to work with it. Some discussion of block visibility serves as a good example of those places where Drupal allows developers to get down into code without modifying Drupal itself. While it&amp;#8217;s a fine discussion, the author fails to mention the &lt;a href=&quot;http://drupal.org/node/60317&quot;&gt;repository of Block visibility snippets&lt;/a&gt;, which has lots of other examples for a budding themer to snack on.&lt;/p&gt;

&lt;p&gt;We also get a very good idea in Chapter 3 on how just a little bit of well-placed code here and there can make a big difference in  Drupal themes. Working with the &lt;a href=&quot;http://drupal.org/project/zen&quot;&gt;Zen theme&lt;/a&gt;, the author takes us through the theme&amp;#8217;s files to show where the key points of control lie.&lt;/p&gt;

&lt;p&gt;Chapter four is a list of core css files and theme functions. It is also completely superfluous. It could be replaced with a couple of &lt;code&gt;grep&lt;/code&gt; or &lt;code&gt;find&lt;/code&gt; commands, or a tutorial for finding theme functions on &lt;a href=&quot;http://api.drupal.org&quot;&gt;api.drupal.org&lt;/a&gt;, which would have longer-lasting benefits for a Drupal themer. A representative of the content in this chapter is:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;theme&amp;#95;admin&amp;#95;block&amp;#95;content&lt;/strong&gt;&lt;br /&gt;
  Formats the content of an administrative block.&lt;/p&gt;
  
  &lt;p&gt;&lt;strong&gt;theme&amp;#95;admin&amp;#95;page&lt;/strong&gt;&lt;br /&gt;
  Formats an administrative page for viewing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It&amp;#8217;s 18 pages of your life that you&amp;#8217;ll never get back.&lt;/p&gt;

&lt;p&gt;That&amp;#8217;s followed by what is easily the standout section of the book. Chapter 5 is all about overriding css and theme functions, and is a terrific discussion on what&amp;#8217;s available to the themer, and how to get at it. It&amp;#8217;s chock full of great information and examples, showing how the default &amp;#8220;Garland&amp;#8221; theme takes the PHPTemplate engine and overrides parts of it itself, and shows how you and your theme could do the very same thing. It&amp;#8217;s an empowering overview of taking control of the theming process.&lt;/p&gt;

&lt;p&gt;Chapter six focuses on designing a theme around the Zen, creating a subtheme. Just a bit of code and some new CSS, and we have a completely different looking site. The big problem here is that the theme we come up with is pretty ugly. Nevertheless, it does show how big results can come from a little tweaking.&lt;/p&gt;

&lt;p&gt;Now that we&amp;#8217;ve taken a pre-written theme and designed a subtheme around it, Chapter seven is all about creating a theme from scratch. Starting with the bare basics and moving into discussions of what variables PHPTemplate makes available, and even how to make your own variables available, this is a grand discussion that shows the full power of the templating engine and how much power is actually there. Again, though, what we&amp;#8217;re creating won&amp;#8217;t be winning any design awards, but I suppose that&amp;#8217;s beside the point.&lt;/p&gt;

&lt;p&gt;The last chapter is about theming the various forms in Drupal, and this again is excellent. There are several steps in the process that can be used to change how forms work, and the author expertly goes through each way, showing where each one is most appropriate, and showing fine examples in the process. If the whole book were this well written, it&amp;#8217;d be a bible of Drupal theming. Unfortunately, it&amp;#8217;s not. The chapter also devolves into unneeded screenshots of most of the Drupal forms, and what functions are used to build them.&lt;/p&gt;

&lt;p&gt;The book ends with a totally unnecessary appendix of every CSS selector included in Drupal core. Once again, a nice &lt;code&gt;grep&lt;/code&gt; command could easily have been used to build this content.&lt;/p&gt;

&lt;h1&gt;What the book gets right&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Chapters 5, 7, and 8 are quite useful, even to an old three-digit-uid user like me. Overriding is a big part of Drupal, not just theming, and it&amp;#8217;s taken on in great style and fine discussion. PHPTemplate is one of the shining stars in Drupal, everyone who uses it owes Adrian a beverage, and the fact that you can use a few pages to talk about how to create an entire Drupal theme from scratch shows its amazing power. It would be hard to get such things wrong, and this book does not. It shows a good knowledge of PHPTemplate and what it&amp;#8217;s very good for. And, though forms aren&amp;#8217;t something that get themed a lot, we have in this book a fantastic reference on how, where, and why you&amp;#8217;d theme forms in Drupal. &lt;/li&gt;
&lt;li&gt;Starting with the Zen theme is practically Best Practice when it comes to theming Drupal, and the author here goes into some depth with this theme, showing code and where some good CSS overriding can make a big difference. It&amp;#8217;s also a wise move to show that the Zen theme is not the last word in theming, and it is possible and even advantageous to create your own theme from scratch. &lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;What the book gets wrong&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;As noted above, there are several places where I thought the content was superfluous. Chapter four could be reduced to a few grep statements, or a discussion of api.drupal.org. While chapter 8 starts off with some fine discussion, it ends up with a bunch of screenshots of forms in Drupal, and where they are in the code. While there might be some good information in here, the screenshots, and number of them, seem over done. Appendix A could also be reduced to a few grep statements, as it simply lists the CSS selectors in all of the css files within Drupal core.&lt;/li&gt;
&lt;li&gt;No book on Drupal is complete without a discussion of Drupal contributions. This book does spend a good deal of quality time with the Zen theme, that is the first and last time contributions are mentioned to any depth. Looming very large in their absence are CCK and Views, two modules that practically every Drupal site will need in its lifespan, and two modules which are complex to theme, and yet very themeable. Any book on Drupal theming that does not even mention these two modules, let alone not show any examples of theming them, is woefully incomplete. Yes, they&amp;#8217;re not core, but neither is the book called &amp;#8220;Drupal 5 &lt;em&gt;Core&lt;/em&gt; Theming.&amp;#8221;&lt;/li&gt;
&lt;li&gt;The graphics in the book are of poor quality. The places where lightly-colored text are used (such as the Garland theme) are very hard to read, and the file listing screenshots are badly pixellated. Every screenshot looks like the poor-quality placeholder images were never swapped out for high quality images.&lt;/li&gt;
&lt;li&gt;The themes we end up designing in the book are, well, ugly. I realize that&amp;#8217;s not the point, but I think that, if the book&amp;#8217;s going to discuss theming and design a theme or two, I would want the themes to be of good quality.&lt;/li&gt;
&lt;li&gt;Just a week or so after I received this book on Drupal 5 Theming, Drupal 6.0 was released. Most of the discussion in the book still applies, as the theming exercises themselves focus on the Zen theme and CSS, but large portions of the book, particularly Chapters 5 and 7, which might be the best part of the book, will need to be rewritten, as Drupal 6 has dramatically increased the number of .tpl.php files, and in the process has made overriding these pieces much easier. Themes themselves have changed in Drupal 6, requiring corresponding .info files, requiring registration via &lt;code&gt;hook_theme()&lt;/code&gt;, and in the removal of &lt;code&gt;_phptemplate_callback()&lt;/code&gt;. Readers coming to Drupal 6 with this book would be well-advised to keep the appropriate &lt;a href=&quot;http://drupal.org/node/132442&quot;&gt;Drupal.org handbook page&lt;/a&gt; open in a tab while reading and experimenting.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;So, what do I think?&lt;/h1&gt;

&lt;p&gt;There are great parts of this book, and there are horrible parts of this book. While I think that there&amp;#8217;s more wrong than right, the parts that are right are very right and worth the price of the book. Someone new to Drupal theming, someone who&amp;#8217;s just not sure what to do, someone who thinks they can just change the color in Garland or mess with Bluemarine and call it a day, these people will get a great deal of worthwhile information out of the 250 or so pages. The book is geared towards people with a good background in HTML and CSS, and it does mention that a &amp;#8216;basic&amp;#8217; knowledge of PHP is helpful. It&amp;#8217;s to PHPTemplate&amp;#8217;s credit that most themers won&amp;#8217;t need to touch too much code, and what needs done is typically simple logic and not difficult. Those places where you can get deep in to PHP and Drupal coding are properly glossed over. &lt;strong&gt;Drupal 5 Themes&lt;/strong&gt; leaves room for an advanced theming book, and that is the appropriate time to have such discussion.&lt;/p&gt;

&lt;p&gt;All in all, I do recommend this book to people who are looking at Drupal and want to know how they can change the look of it to fit their design. It does show the power of the Drupal theming layer, and how much Drupal&amp;#8217;s output can be changed through, not just CSS, but some simple and well-placed PHP code as well. &lt;strong&gt;Drupal 5 Themes&lt;/strong&gt; is a worthwhile introduction to Drupal theming, and deserves its place among the current crop of Drupal&amp;nbsp;books.&lt;/p&gt;
</description>
 <comments>http://oif.eafarris.com/content/review-drupal-5-themes#comments</comments>
 <category domain="http://oif.eafarris.com/tags/design">design</category>
 <category domain="http://oif.eafarris.com/tags/drupal">Drupal</category>
 <category domain="http://oif.eafarris.com/tags/planet-drupal">planet drupal</category>
 <category domain="http://oif.eafarris.com/tags/web">Web</category>
 <pubDate>Sat, 16 Feb 2008 16:09:45 -0500</pubDate>
 <dc:creator>eafarris</dc:creator>
 <guid isPermaLink="false">2561 at http://oif.eafarris.com</guid>
</item>
<item>
 <title>CCK Theming in Drupal 4.7</title>
 <link>http://oif.eafarris.com/cck_theming_in_drupal_4_7</link>
 <description>&lt;p&gt;As I go through a test site for One Inch Frame&amp;#8217;s update to &lt;a href=&quot;/freelinking/Drupal&quot; class=&quot;freelinking&quot;&gt;Drupal&lt;/a&gt; 4.7, I&amp;#8217;m doing something different with my wiki nodes and web link nodes. Right now, I&amp;#8217;m using &lt;a href=&quot;http://www.drupal.org/project/flexinode&quot;&gt;flexinode&lt;/a&gt; to build a custom wikinode type, and am using &lt;a href=&quot;http://www.drupal.org/project/weblink&quot;&gt;weblink&lt;/a&gt; for the large amount of links that I accumulate in my &lt;a href=&quot;directory&quot;&gt;links directory&lt;/a&gt;, the sort of thing that I used to post to del.icio.us. The weblinks module has been discontinued in favor of the &lt;a href=&quot;http://drupal.org/node/24719&quot;&gt;links bundle&lt;/a&gt;, but that promising project is still not ready, and my needs are such that that project might just be overkill. I&amp;#8217;ve still got my eye on it, though.&lt;/p&gt;

&lt;p&gt;With the 4.7 version, I&amp;#8217;ve decide to take a good hard look at the &lt;a href=&quot;http://www.drupal.org/project/cck&quot;&gt;Content Construction Kit&lt;/a&gt;, as it is basically the future of flexinode and Drupal. And it&amp;#8217;s also really, really cool.&lt;/p&gt;

&lt;p&gt;So I created a simple node type for wikinodes, and a type for web links. One of the things I want to do differently this time around is build in attribution to my web links, so I can give credit to the source where I found the link. So, another CCK content type for web link source is needed, and I can use the built-in &amp;#8216;nodereference&amp;#8217; field type to link a web link to its source.&lt;/p&gt;

&lt;p&gt;And, out of the box, it works great. I can add attribution sources and they show up in a drop-down in the web link content creation form. Super cool. The default look of this field when viewing a web link makes the attribution hotlinked to the attribution&amp;#8217;s source node. It boggles my mind to think of some of the ways smart people are going to take advantage of the CCK, and, particularly, its nodereference field type. There&amp;#8217;s also a userreference which does the same thing for users, for completeness.&lt;/p&gt;

&lt;p&gt;The way CCK-created content looks is a fine default, but, theming them will be necessary in almost every case. Fortunately, the CCK download comes with a theme/ directory with documentation and samples.&lt;/p&gt;

&lt;p&gt;So, the first thing I want to do for all my CCKreated (heh, like it? made it up myself) nodes is to remove the label. The CCK allows theming at the field level or up at the node level. To remove the labels globally for all CCKreated content, there&amp;#8217;s some code to add to the template.php file, then your PHPTemplate-based theme will call field.tpl.php files to render all CCK fields. Just removing the printing of the label is fine here:&lt;/p&gt;

&lt;p&gt;So, my field.tpl.php looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;div class=&quot;field field-type-&amp;lt;?php print strtr($field_type, &#039;_&#039;, &#039;-&#039;) ?&amp;gt; field-&amp;lt;?php print strtr($field_name, &#039;_&#039;, &#039;-&#039;) ?&amp;gt;&quot;&amp;gt;
&amp;lt;div class=&quot;field-items&quot;&amp;gt;
  &amp;lt;?php foreach ($items as $item) { ?&amp;gt;
    &amp;lt;div class=&quot;field-item&quot;&amp;gt;&amp;lt;?php print $item[&#039;view&#039;] ?&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;?php } ?&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;While that takes care of theming the individual fields, for my web links I want to theme the whole node. PHPTemplate allows for different themes to be applied to different content types, and CCK extends that to its own types. So, to theme a web link CCKreated node, I write a node-content-web_link.tpl.php. This will override the theming of the individual fields, and give me control over the content as a whole. As CCK exposes its fields via a &lt;code&gt;$field_&amp;lt;fieldname&amp;gt;&lt;/code&gt; array, this, too, is pretty simple:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;div class=&quot;node&amp;lt;?php if ($sticky) { print &quot; sticky&quot;; } ?&amp;gt;&amp;lt;?php if (!$status) { print &quot; node-unpublished&quot;; } ?&amp;gt;&quot;&amp;gt;
  &amp;lt;?php if ($picture) { print $picture; }?&amp;gt;
  &amp;lt;h2 class=&quot;headerstyle&quot;&amp;gt;&amp;lt;a href=&quot;&amp;lt;?php print $node_url?&amp;gt;&amp;lt;span class=&quot;dquo&quot;&amp;gt;&quot;&amp;lt;/span&amp;gt;&amp;gt;&amp;lt;?php print $title?&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/h2&amp;gt;
  &amp;lt;span class=&quot;submitted&quot;&amp;gt;&amp;lt;?php print $submitted?&amp;gt;&amp;lt;/span&amp;gt;
  &amp;lt;span class=&quot;content&quot;&amp;gt;
    &amp;lt;p class=&quot;weblink_description&quot;&amp;gt;&amp;lt;?php print $field_description[0][view] ?&amp;gt;&amp;lt;/p&amp;gt;
    &amp;lt;p class=&quot;weblink_url&quot;&amp;gt;&amp;lt;?php print $field_url[0][view]?&amp;gt;&amp;lt;/p&amp;gt;
    &amp;lt;p class=&quot;weblink_attribution&quot;&amp;gt;via &amp;lt;?php print $field_attribution[0][view]) ?&amp;gt;&amp;lt;/p&amp;gt;
  &amp;lt;/span&amp;gt;
  &amp;lt;span class=&quot;taxonomy&quot;&amp;gt;Categories: &amp;lt;?php print $terms?&amp;gt;&amp;lt;/span&amp;gt;
  &amp;lt;?php if ($links) { ?&amp;gt;&amp;lt;p class=&quot;internallinks&quot;&amp;gt;&amp;amp;raquo; &amp;lt;?php print theme(&#039;links&#039;, $node-&amp;gt;links, &#039;&amp;amp;nbsp;&amp;amp;middot;&amp;amp;nbsp;&#039;)?&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;?php }; ?&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That&amp;#8217;s nice, and generic. I need a couple more things to make this just what I&amp;#8217;m after:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The url isn&amp;#8217;t hot. It should be linked to itself.&lt;/li&gt;
&lt;li&gt;The attribution goes to the attribution node, but I&amp;#8217;d much rather it go directly to the attribution&amp;#8217;s site, which is contained in a URL field as part of the attribution node.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first one is very simple, just wrap the url in an href of itself:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;p class=&quot;weblink_url&quot;&amp;gt;&amp;lt;a href=&quot;&amp;lt;?php print $field_url[0][view]?&amp;gt;&amp;lt;span class=&quot;dquo&quot;&amp;gt;&quot;&amp;lt;/span&amp;gt;&amp;gt;&amp;lt;?php print $field_url[0][view]?&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Getting to the last part will require a tiny bit of programming. What we want, instead of a link to the attribution node (which is a cck-derived content type of content-web&amp;#95;link&amp;#95;source) we want the link to go directly to the url within that node. To start, we&amp;#8217;ll need to call a custom theme function instead of printing the $field_attribution stuff:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;p class=&quot;weblink_attribution&quot;&amp;gt;via &amp;lt;?php print theme(&#039;oif_attribution&#039;, $field_attribution[0][nid]) ?&amp;gt;&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, we write that theme function. It goes in template.php, and, for
completeness&amp;#8217; sake, we call it &lt;code&gt;andreas03_oif_attribution()&lt;/code&gt;, since
andreas03 is the name of the theme. It gets the nid of the attribution node passed to it::&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?php
function andreas03_oif_attribution($nid) {
  $attribution = node_load($nid);
  $output = &#039;&amp;lt;a href=&quot;&#039; . $attribution-&amp;gt;field_url[0][value] . &#039;&quot;&amp;gt;&#039; .  $attribution-&amp;gt;title . &#039;&amp;lt;/a&amp;gt;&#039;;
  return $output;
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And, there it is. A fully themed CCK node. Drupal is so freakin&amp;#8217; cool. You&amp;#8217;ll see these new nodes when I roll out the new version of One Inch Frame, based on Drupal 4.7, which is still several weeks away. There are just so many cool things that I want to do, that are now&amp;nbsp;possible.&lt;/p&gt;
</description>
 <comments>http://oif.eafarris.com/cck_theming_in_drupal_4_7#comments</comments>
 <category domain="http://oif.eafarris.com/tags/drupal">Drupal</category>
 <category domain="http://oif.eafarris.com/tags/planet-drupal">planet drupal</category>
 <pubDate>Tue, 09 May 2006 08:35:14 -0400</pubDate>
 <dc:creator>eafarris</dc:creator>
 <guid isPermaLink="false">1959 at http://oif.eafarris.com</guid>
</item>
</channel>
</rss>
