This chapter explains hook_page_alter(), which is another alter hook new to Drupal 7 and to the theme layer. Each page rendered by Drupal is contained within an array where the theme is able to go in and rearrange, delete or duplicate specific page elements.
Additional resources
This chapter shows some general best practices for keeping your template.php file clean as well as making it easier for designers to work primarily with the template files when possible to avoid them having to make too many changes to template.php. Specifically, some HTML classes are removed from the ninesixtyrobots_comment_form() function in template.php and moved to the comment-form.tpl.php template file, which is specified as an option in the ninesixtyrobots_theme() function. The rendering logic is also removed from the theme function and into a preprocess function so that it can be passed in as a variable to the new template file.
Additional resources
The ability of having alter hooks within the theme layer starts to blur the line between the logic and presentation, and so there are a few things to be aware of when using hook_form_alter() from the theme layer. The biggest thing to know is that the form rendering process has already gone through the creation and validation preparation process at the module layer, and so you shouldn't be drastically changing the functionality of a form at the theme layer. This form alter hook at the theme layer is primarily for aesthetic clean-up, styling and additional design. This chapter gives some specific examples of things to watch out for.
Additional resources
There are four alter hooks that are now available to the theme layer in Drupal 7. This chapter walks through two of those hooks, hook_css_alter() and hook_js_alter(). These hooks allow the theme layer to reorder, delete or replace specific CSS or JavaScript files that are being loaded by Drupal core or other contributed modules.
Additional resources
This lesson goes through the process of creating Theme Settings so that administrators of a theme are able to turn on and off specific features within the the theme, as well as specify other relevant settings.
Note: Twitter has recently shut down their v1 REST API so this lesson's site_slogan adjustment no longer works (it will always return no values because there is no API data found). The core concepts of how to create theme settings are still correct, you just won't be able to see the output from Twitter.
Additional resources
This chapter goes through the process of adding a specific form id to the theme registry with the hook_theme() function, which allows the creation of a new function that targets a specific form. Specifically in this chapter, comment_form is added to the theme registry so that we can create a ninesixtyrobots_comment_form() function in order to add a column to the comment form so that the name and subject fields are displayed side-by-side.
Additional resources
Provides an overview of what is covered in the Theming Basics series and gives a preview of what is yet to be covered within the Advanced Theming video.
Walks through the process of adding a screenshot to you theme so that it'll show up properly within the theme administration page, following the screenshot directions found on Drupal.org, and using the Skitch screenshot app (you can use whichever screenshot app you like).
Additional resources
Takes a tour through some of the more useful template variables, and more ways of determining the available variables by adding the following code to a page template:
Walks through the process of copying the default node.tpl.php file from the core node module into the theme, and then customizing the output specific to individual in order to match the design. See how to add specific variables, when to use conditional if statements and the best way to debug and iterate through this process.
Additional resources
In this chapter, we add some sidebar and footer regions to the page via the .info files, and printing those new regions out in our page template file, adding some blocks to help with testing. We also talk about Devel and Krumo, and how we can use those to find out everything that is available in out page array, using the dsm() function. While inspecting out page array, we point out the differences between elements and properties within renderable arrays.
Additional resources
We'll go a step further with our preprocess functions and look at working with node variables, and how to limit new variables to only specific content types.
Additional resources
This video walks through the process of replacing static content in the page.tpl.php file with dynamic variables. Joe talks about the html.tpl.php file as well as pointing some of the important variables that should be included within the theme.
Additional resources
This chapter covers some really handy browser extensions in the process of theming. For Firefox, there's the Web Developer Toolbar for turning off and on JavaScript, resizing the browser window to different sizes, and inspecting elements. It also has the capability to test changes to CSS files in a format that is easy to copy and paste into the source file. We also show off the basics of the popular Firebug extension, and the equivalent functionality that is now built in to webkit-based browsers such as Safari and Chrome.
Additional resources
Continuing on our work with preprocess functions, we look at how to add a new variable for our template files to use. We also see how to change the output based on whether the user is logged in or not, and how to add a variable to the t() function.
Additional resources
In this chapter, we'll walk through some of the best practices for filling out a stock Drupal site so that you can start to have some dummy content generated by different users and tagged with different taxonomy tags. We'll step through creating content with the devel generate module, and then do some other site preparation tasks such as creating some menu items and adding a shortcut link to the performance page so that you can quickly access the clear cache button.
Additional resources
In this video we will look at overriding a theme function instead of working with the template files. We will be modifying the breadcrumb using theme_breadcrumb(). to do this we'll use the Theme Developer module to help us find what we're looking for, and then we'll walk through how to override.
Additional resources
Theme Developer module (Drupal.org)
960 Robots
In this video we will see how we can create our own preprocess function for a theme function (not just templates). We're going to use this to display the user's full name on the site wherever the the username would normally appear. We start by creating a full name field, and then show how to get this working on our site.
Additional resources
In this video we will look at how to add CSS and JavaScript to our site using drupal_add_css()
and drupal_add_js()
. We will also show using these functions to conditionally add the CSS and JavaScript, within our page preprocess function.
Additional resources
In this video we'll see how we can create our own template suggestions. We'll do this in our node preprocess function to create a new node template that will be used depending on the day of the week.