Presentation is loading. Please wait.

Presentation is loading. Please wait.

What you don’t know you don’t know about Drupal 6 Dan Harris daneesia on drupal.org.

Similar presentations


Presentation on theme: "What you don’t know you don’t know about Drupal 6 Dan Harris daneesia on drupal.org."— Presentation transcript:

1 What you don’t know you don’t know about Drupal 6 Dan Harris dharris1@stanford.edu daneesia on drupal.org

2 Drupal is Truly Amazing Because You can hook into virtually any part of the execution Because You can hook into virtually any part of the execution Because the theming is so elegantly layered Because the theming is so elegantly layeredBUT… Much of its amazement is un- or under- documented Much of its amazement is un- or under- documented Too often the docs that do exist live buried in some thread on drupal.org/node/NNNNN Too often the docs that do exist live buried in some thread on drupal.org/node/NNNNN

3 This Session is for you if… You've ever wondered "Where the #$%!^ does THAT HTML come from" (and how to override it)? You've ever wondered "Where the #$%!^ does THAT HTML come from" (and how to override it)? You've ever wondered if there are more.tpl.php files than what Views claims to be available after clicking the Theme: Information link You've ever wondered if there are more.tpl.php files than what Views claims to be available after clicking the Theme: Information link You're curious how to build a view using the Views API You're curious how to build a view using the Views API You're curious how to display CCK fields You're curious how to display CCK fields –in regions other than the primary content area –directly from a.tpl.php file –while empowering your content editors to edit entire pages in one place without using Panels or other modules.

4 Agenda Methods for discovering Methods for discovering –where that HTML is coming from –how Themer may be helpful –how to find what you’re looking for without Themer What sorts of files and functions are What sorts of files and functions are –begging to be overridden –where they may be hiding Some Useful Views API functions/CCK variables Some Useful Views API functions/CCK variables Q&A Session Q&A Session

5 Where the #$%^&! is that HTML Coming From??? Motivation: I typically find it harder to debug CSS than get the output I want Motivation: I typically find it harder to debug CSS than get the output I want Example: Example:............ ……… Where does the red markup come from? Where does the red markup come from? How can it be overridden? How can it be overridden?

6 Where did that Red Markup Come From? Ask Themer

7 And When Themer Fails to Tell You? Use the information at hand as a starting point: Use the information at hand as a starting point: –What is the source of this page/block Selected Template? View? Feed? Panel? CCK? Selected Template? View? Feed? Panel? CCK? Answering that should give a major clue as to where to begin your search Answering that should give a major clue as to where to begin your search –Next search through the files in the base directory If the module contains a “theme” directory, start there If the module contains a “theme” directory, start there If all else fails, check /includes/theme.inc and other.inc files in /includes or the /modules directory. If all else fails, check /includes/theme.inc and other.inc files in /includes or the /modules directory. Returning to our example, the three highlighted lines came from 3 sources! Returning to our example, the three highlighted lines came from 3 sources!

8 Overriding Template Files What Can be Overridden? What Can be Overridden? –Chances are, if it ends in.tpl.php, it can be overridden. –Exception: the module author “forgets” to make a file “overridable” Example: date-navigation.tpl.php Example: date-navigation.tpl.php –A well designed template system for a given module will also allow for overriding based on naming “suggestions” –Other times, you may be able to create your own.

9 Overriding Theme Functions What can be overridden? What can be overridden? –Chances are if it starts with theme_, template_, or phptemplate_, it can be overridden –Chances are if it’s in your “master” theme template.php file, it can be overridden –Override by pasting the code into your custom template.php file pasting the code into your custom template.php file changing the function name to YOURMODULE_ changing the function name to YOURMODULE_ changing the code as needed changing the code as needed –Note: in most cases you want to add a condition and only override what’s necessary Don’t forget to clear your theme registry! Don’t forget to clear your theme registry!

10 Theme Override Example: Calendar Empty Day Original Original function theme_calendar_empty_day($curday, $view) { if ($view->date_info->calendar_type != 'day') { if ($view->date_info->calendar_type != 'day') { return ' '."\n"; return ' '."\n"; } else { else { return ' '. t('Empty day').' '; return ' '. t('Empty day').' '; }} Overridden Function Overridden Function function sls_calendar_empty_day($curday, $view) { if ($view->date_info->calendar_type != 'day') return ''; if ($view->date_info->calendar_type != 'day') return ''; else { else { return ' '. t('Empty day').' '; return ' '. t('Empty day').' '; }}

11 Overriding Views Template Files Virtually all views template files (ending in.tpl.php) may be overridden Virtually all views template files (ending in.tpl.php) may be overridden –Regardless of if they show up after clicking the Theme: information link –Views plugins don't report available templates/overrides –Not all views native template files displayed Example: views-exposed-form.tpl.php may be overridden for a given view, but you won’t see that naming suggestion anywhere on the theme: information link Example: views-exposed-form.tpl.php may be overridden for a given view, but you won’t see that naming suggestion anywhere on the theme: information link In the Views UI, overrides are listed from least-specific to most. In the Views UI, overrides are listed from least-specific to most. For views and many plugins, template suggestions naming patterns found in the UI typically work, but aren't documented. For views and many plugins, template suggestions naming patterns found in the UI typically work, but aren't documented.

12 Wait, why don’t I just want to solve all my problems with CSS again? 1. Unless you override, you may be forced to use the various classes that are output from CCK and views 2. You need to comment your CSS least you forget why you have CSS like #view-id.field-field-0 {} 3. The CSS will be harder to maintain in most cases. –For example when want to add more fields to the view or change the view layout 4. IMO, the CSS approach will require more "debugging” and will be more prone to cross-browser issues. 5. Overriding allows you to output the exact layout desired 6. The sooner you get your hands dirty with code, the more comfortable you’ll be later.

13 A few Useful CCK Variables $field_YOURFIELD_rendered $field_YOURFIELD_rendered –Printing this field will output it according to your Display settings (in the same manner as it would come out in the content area) –Use it for finer granularity within a.tpl.php file and/or in conjunction with the drupal_set_content() API call. If you’d like to insert some HTML around your filed, use $field_YOURFIELD[#]['view/safe/email/etc'] If you’d like to insert some HTML around your filed, use $field_YOURFIELD[#]['view/safe/email/etc'] –Example: if (!empty($field_sidebar_right_other[0]['value'])) { echo ($field_sidebar_right_other[0]['value']; echo ($field_sidebar_right_other[0]['value']; } Works in.tpl.php files and wherever else these variables have been made available. Works in.tpl.php files and wherever else these variables have been made available.

14 Views_embed_view() Embed a view anywhere & any time: Embed a view anywhere & any time: views_embed_view('view_name', 'display_name', args) views_embed_view('view_name', 'display_name', args) –'view_name' is the machine name you assigned to your view –'display_name' is either 'default' or 'displayType_#' e.g. 'page_1' or 'block_3' True regardless if you provide your own names for these displays True regardless if you provide your own names for these displays –args: the optional arguments to be passed to the view set to either $arg1, $arg2, $arg3 if multiple arguments are needed (e.g. $nid, $uid, and $tid) set to either $arg1, $arg2, $arg3 if multiple arguments are needed (e.g. $nid, $uid, and $tid) 'arg1+arg2+arg3' (note single quotes) if multiple work together to form one argument (e.g. term IDs) 'arg1+arg2+arg3' (note single quotes) if multiple work together to form one argument (e.g. term IDs)

15 Building a Dynamic View Use Case: you want to set a dynamic filter without user input using a node reference Use Case: you want to set a dynamic filter without user input using a node reference $filter = array(); $related_courses_view = views_get_view('related_courses_by_discipline'); $display = 'default'; $related_courses_view->set_display($display); $filter = $related_courses_view->get_item($display, 'filter', 'field_course_discipline_nid'); // Grab the node id from the node reference value set for this node $filter['value'] = $field_course_discipline[0]['nid']; $related_courses_view->set_item($display, 'filter', 'field_course_discipline_nid', $filter); $related_courses_view->build($display); $content.= ' Other '. $field_course_discipline[0]['view']. ' Courses: '; $content.= $related_courses_view->render($display); echo $content;

16 Where to go from Here Views API: http://views.doc.logrus.com/ Views API: http://views.doc.logrus.com/http://views.doc.logrus.com/ CCK Docs: http://drupal.org/node/101723 CCK Docs: http://drupal.org/node/101723http://drupal.org/node/101723 Views Docs: http://drupal.org/handbook/modules/views Views Docs: http://drupal.org/handbook/modules/viewshttp://drupal.org/handbook/modules/views Overriding Themable Output: http://drupal.org/node/341628 Overriding Themable Output: http://drupal.org/node/341628http://drupal.org/node/341628 Check out the Examples Module: Check out the Examples Module: –http://drupal.org/project/examples http://drupal.org/project/examples (This module hasn't received the publicity it deserves) (This module hasn't received the publicity it deserves)

17 Q&A Session

18 Thanks! Feel free to contact me: Feel free to contact me: –dharris1@stanford.edu dharris1@stanford.edu –95slug@gmail.com 95slug@gmail.com –daneesia on Drupal


Download ppt "What you don’t know you don’t know about Drupal 6 Dan Harris daneesia on drupal.org."

Similar presentations


Ads by Google