Our latest podcast, Episode 52: Drupal Community Leadership, has Addi joined by Larry Garfield (Crell), Greg Dunlap (heyrocker), and Gábor Hojsty (Gábor Hojsty); three people who have
Release Day: More Twig Tutorials
Blog postThis week, Leanna Pelham of KnpUniversity continues to show you how to become a Twig expert by demonstrating Twig goodies such as template inheritance, functions, tests, for and if syntax, debugging techniques, macros, and other advanced tips and tricks. Each lesson is a bite sized tutorial and includes downloadable site code that will get you up and running with Twig without getting overwhelmed.
In this tutorial we're going to play with some extra nice things you can do with Twig. We're going to get expert control of our blocks with the block function, work with concatenating strings, controlling our whitespace, and using undefined variables with the default filter. We'll wrap things up with a look at escaping HTML. Whenever you render content that may have been filled in by the user, you need to escape it. This prevents people from writing HTML tags that you don’t want or, worse, JavaScript code that could be used for cross-site scripting attacks.
Using a base layout is very common, and we’ve implemented that in the previous tutorial. Sometimes you also need to include some other templates on only select pages. In this tutorial you are going to add a sales banner to the pages using the include
function, and working with the variables we can pass there.
Additional resources
Be sure to check the documentation for the version of Twig in your codebase for the correct syntax and usage.
In our last tutorial we have things set up to include a new template, but we are currently getting an error, due to not passing the correct variable. In this tutorial we'll see how to fix this problem by adding a "defined" test to our code, which will check to see if the variable is defined in the _banner.twig template
, and default to "lightblue" if it is not.
Additional resources
Our products are printing out a bit weird right now because they’re floating, but not breaking correctly. To fix this, we need to wrap every three products in their very own row. In this tutorial, you will use a "divisibleby" test to see if the item number we’re on is divisible by three, and then loop through them. We'll also clean up our if
statement for our background color, by implementing an inline if
syntax.
In this tutorial we're going to purposely make some common Twig mistakes, debug them, and figure out how to fix them. We'll also look at a way to make parts of your Twig code easily reusable, using macros.
This week we have a ton of new tutorials for you to enjoy. We're very happy to bring back our friends from KnpUniversity to provide a great little series on the Twig templating system, and we're also wrapping up the entire O'Reilly Using Drupal book series with the final tutorials.
In this short series you will learn how to find and evaluate Drupal modules for your project. This first tutorial will show you where to find modules on Drupal.org, and various ways you can use Drupal.org's search tools.
Additional resources
Drupal.org Modules page
Drupal module categories
Similar modules group
Drupal case studies
Planet Drupal
An open source project’s strength comes from the power of its base of contributors, and a Drupal project is no different. Although every line of code added or changed in Drupal core goes through rigorous peer review, contributed modules are more of a Wild West where anyone who jumps through a few basic hoops can add modules for everyone to download. Whether or not a module is well maintained, its overall code quality, and how well used it is in the overall community are all important factors for you to consider when selecting modules. This tutorial will talk about determining these factors by closely inspecting the tools Drupal.org provides, starting with the central feature of all Drupal modules: the project page.
By far, the best way to keep up-to-date on which modules are the most useful, and to ensure that those modules do what you need, is to actually get directly involved and help. The Drupal community offers a myriad of ways for everyone, from the person who just installed Drupal for the first time yesterday to the person who has been coding since she was in diapers, to give something back. In this tutorial we'll look at all of these options and explain how you can dive in.
Additional resources
Many businesses, both large and small, would like to take better advantage of their web presence by selling their products or services directly online. Setting up ecommerce, however, can be a very daunting task. In this series you will create an online t-shirt shop, and in the process you will learn how to use the basic pieces of Drupal Commerce, including setting up a Paypal payment system, along with an introduction to the Feeds module, for importing our catalog, and the Rules module, to set up taxes. In this lesson we'll kick things off by reviewing the requirements for the Sweet Tees store, and discuss how we'll be going about implementing them.
Additional resources
Drupal Commerce is a complete package for running an online store. As such, it actually contains numerous submodules that each implement features of an online store, and can be turned on or off depending on the precise functionality required. In this section, we’ll look at each module in turn, and outline its purpose and where it fits. In this lesson we'll get an overview of the major components of Drupal Commerce, including:
- Carts, checkout, taxes, and payment
- Customers and orders
- Products and pricing
- Additional Drupal Commerce add-ons
Additional resources
Before we get to the first step in creating our store—adding products—it’s worth taking some time to discuss and understand how Drupal Commerce treats products within the system. While product management may appear unintuitive at first, the product management features in Drupal Commerce are designed to allow for maximum flexibility. In this lesson we'll explain what product types are, and take a look at both the required fields that come with them, and the custom fields you can add.
Additional resources
The first step in setting up our online t-shirt store is to turn on a formidable array of modules to enable the Drupal Commerce module, and then set up product types for the merchandise that Sweet Tees sells: T-shirts and stickers. In this lesson we'll get the right modules enabled, configure our two product types, and then create some sample products to make sure it's all working the way we expect.
Additional resources
The Feeds module provides the capability to ingest data from any number of different sources and transform it into native Drupal constructs. It’s a versatile tool that can be used for things such as large-scale data migration, automatically populating a block of recent content from external sites, or synchronizing content posted among multiple sites. In this lesson we'll learn how Feed importers are created with the three main pieces of Fetchers, Parsers, and Processors.
Additional resources
Using Drupal, 2nd edition
Using Drupal source code
Feeds project
Now that we’re familiar with the Feeds module’s data import tools, let’s turn our attention to importing t-shirt products for Sweet Tees. Sweet Tees has kindly furnished us with a comma-separated values (CSV) file containing all of their t-shirt product data for this purpose. CSV is a common data export format from databases and spreadsheet programs. A CSV file is a simple text file that encodes a data set with each record on its own line, and a separator (such as a comma or tab) between the data values. In this lesson we'll create a feed importer for CSV files, map the CSV data to our Drupal Commerce products, and then actually import the CSV product data into our store.
Additional resources
Now that all of this groovy product data is showing up fine in the administrative interface, there’s just one problem: how do we expose these products on our public website to our customers? And further, how do we avoid displaying a product catalog with 25 entries in it, when from a customer’s point of view we only sell four products (three t-shirts and a sticker)? In this lesson we'll get an overview of how Drupal Commerce handles this with the concept of product displays and product attributes.
Additional resources
In this lesson we'll put what we just learned into action by creating a content type for product displays, and a few sample products to get the hang of how things work.
Additional resources
In this lesson we'll create a nice interface for browsing our products. We will categorize our product displays using the taxonomy system to get our like items grouped together. We'll walk through the process for creating a catalog vocabulary and terms, and then configure the content type and product type to bring it all together.