Creating and Theming Custom Content Types

1,557 views

Published on

Heather Rodriguez's presentation for the October UMD Drupal Users Group monthly meeting on creating and customizing content types.

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,557
On SlideShare
0
From Embeds
0
Number of Embeds
36
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Creating and Theming Custom Content Types

  1. 1. Creating and Theming Custom Content Types<br />Heather Rodriguez<br />UMD Drupal Users Group<br />October 5th, 2011<br />
  2. 2. What is a Content Type?<br />Node: the most basic unit of content<br />Made up of fields of information (ex. Title, Body, URL, etc.)<br />Nodes belong to content types based on fields they share in common<br />Default content types: article (news), blog entry, basic page, book page, forum and poll<br />
  3. 3. Why Create Custom Content Types?<br />Easily and quickly create new nodes that will collect and display the same fields of information<br />Images<br />File upload<br />Text fields<br />Teasers<br />Links<br />etc. <br />
  4. 4. Custom Content Type Example<br />Faculty Bios<br />Name<br />Department<br />Areas of Expertise<br />Research Projects<br />Contact Information<br />Educational background<br />
  5. 5. Customizing Content Types through Template Overrides<br />Copy the content of node template (/sites/all/theme/node.tpl.php)into a blank file <br />Save as node--your-content-type.tpl.php into the templates folder to override the default node template <br />Two dashes after node for Drupal 7, 1 for 6<br />You MUST FOLLOW this naming convention<br />Double-check the machine name of your content type<br />
  6. 6. Customizing Content Types (cont.)<br />Expose array names for styling<br /><?phpprint_r(array_keys($content)) ?>include <br />Print the arrays that you need to display on the page<br /><?php print render($content [’arraynamehere']) ?><br />Add your HTML and CSS around the arrays<br /><h3><?php print render($content [’arraynamehere']) ?></h3> or<br /><p class=“paragraphstyle”><?php print render($content[‘arraynamehere’]) ?></p><br />
  7. 7. Flush the Theme Cache! <br />In order to see the effects of your styling, you must empty your theme cache!<br />Configuration > Performance > Clear all caches<br />
  8. 8. Customizing Fields<br />To modify a specific field rather than the entire content type (useful for separating field label from field items):<br />Make a new copy of the field template file (field.tpl.php located in Modules < Field < Theme) and put it into your theme’s template folder (Sites < All < Themes <Templates)<br />Put your HTML and CSS around the field label or items, depending on what you want to modify<br />Save file as field-- field_machinename.tpl.php<br />
  9. 9. Tips <br />You can use these same methods of template overrides for Views, Forms, Pages, etc. as well<br />For a full list of possible tpl.php overrides, check out Drupal 7 Template Suggestions: http://drupal.org/node/1089656<br />Don’t forget to save template overrides in your theme folder!<br />If you don’t see any changes, flush the theme cache.<br />Watch Lin Clark’s Intro to Drupal 7: Theming Fields and Nodes with Templates: http://youtu.be/sxZQqgvJk3s<br />

×