Getting down to the actual templates we want to render, we need to get a handle on Twig, a language that feels a lot like PHP, but was made specifically to be awesome at doing templating tasks, like looping, rendering other templates, and handling layouts. In this lesson, we'll go over the basic Twig tags, and extend a base layout to get our page looking the way we want.
Additional resources
In this lesson, we're going to get things all set up using Composer. If you are not familiar with Composer, you can watch the Wonderful World of Composer tutorial to get up to speed. Once we have Symfony installed, we'll take a tour of the directory structure, and then we'll get things set up to start developing our application with Git.
Apache Notes
If you’re using Apache instead of PHP 5.4's built-in web server, and you've downloaded the project to your Apache document root, then you can go to http://localhost and find your way to the config.php script at http://localhost/starwarsevents/web/config.php. The URL for your app will be http://localhost/starwarsevents/web/app_dev.php.
Fixing Permissions Issues
The easiest permissions fix is to add a little umask
function to the top of 2 files. Pop open your project in your favorite editor (we love PhpStorm). Open up app/console and web/app_dev.php. You’ll see a little umask
line there. Uncomment this:
#!/usr/bin/env php
<!--?php
umask(0000);
// ...
What the heck? The umask
function makes it so that cache and logs files are created as 777 (world writable). Once you’re done, set the permissions on the two cache and logs directories:
$ chmod -R 777 app/cache/* app/logs/*
You shouldn’t have any more issues, but if you do, just set the permissions again.
This method can be a security issue if you’re deploying to a shared server. Check out Symfony’s installation chapter for details on other ways to setup your permissions.
Additional resources
Symfony website
Symfony installation documentation
Composer website
When it comes to rendering a page, the application compares the URL against the routes until one matches, Symfony reads the _controller
key and executes that function. The page you want to render is built in the function. Controller functions are dead-simple, and there’s just one big rule: it must return a Symfony Response object. In this lesson, we'll build our Response, take a look at JSON, and then render the template using the Symfony templating service.
Starting in Symfony 2
CourseFree Halloween Icon Set
Blog postWith Halloween just around the corner, I thought it might be fun to hand out some tasty treats. Don't worry, you're not getting fruit or pennies. It's something much more fun! I designed a custom Halloween icon set, which is free to download and use however you want. With Drupalize.Me's scary good Drupal training, it's fitting that these icons can spook, sweeten, or surprise your next project.
Earlier this year, my colleague wrote about how we've started using CasperJS at Lullabot to perform regression testing. I didn't have much chance to dig into it until recently, when we decided to implement some tests for Drupalize.Me. So far, I'm really enjoying CasperJS—except when something in my test simply doesn't work, and I spend hours asking CasperJS to take screenshots using console.log(), trying to discover what's happening. Fed up with this process, I wanted a debugger...
Before we can translate the various site-wide variables, like the site name or slogan, we need to let Drupal know which ones we want to make translatable. To do this, we’ll need to use the Variable translation module from the Internationalization package. In this lesson we'll enable a multilingual variable so that we can see how to translate the site name.
Additional resources
Translated content on a Drupal is all shown at the same time by default. The Internationalization module will let you display only content that is relevant to the language currently in use, which is referred to as "content selection." In this lesson we're going to configure our site's content selection and the test it out to make sure it working as expected.
Additional resources
So far we’ve got a nice start with getting our site translated, but everything is not quite smooth yet. We have translations for some of our content and menu items, but we're seeing all the content at the same time. You will also see some stray interface text still in English. To take our multilingual site further and really make it shine, in this lesson we're going to turn to a package of modules called Internationalization (i18n). There is a central Internationalization module, which comes packaged with a handful of other modules designed to work together to extend core’s multilingual features.
Additional resources
Internationalization (i18n) project
Using Drupal, 2nd edition
Using Drupal source code
With our interface taken care of, now we can configure multilingual support for our content. That is, we need to be able to identify which language a given piece of content is written in and then create translations. So, we already have articles, and we need to add a knowledge base to the site as well. For both of these types of content, we’ll need to identify the language they are written in, as well as provide related, linked translated versions. In this lesson we'll enable the core Book module for our knowledge base, enable multilingual content, and start translating our knowledge base.
Additional resources
When it comes to translating your site’s content in Drupal 7, we have two possibilities. There is the core “Content translation” module and the contributed “Entity translation” module. They have quite different approaches to translation. So, in this lesson we'll compare the Content and Entity Translation modules, and take a look at how node translations work.
Additional resources
Video about the difference between Content and Entity
Using Drupal, 2nd edition
Using Drupal source code
Today we invite you to take a closer look at content translation in Drupal.
One of many new features in Drupal 8, made possible by the configuration management system, is the ability to add a default image style to your theme, instead of needing to use a module in tandem with your theme, or creating the image style by hand. Here's a look at working with this new feature in Drupal 8.
In this episode, Joshua Mitchell, CTO at the Drupal Association talks with Amber Matz about the exciting initiatives in the works for drupal.org and associated sites. We also talk about how the community, including the D.A.
Today a highly critical security update (SA-CORE-2014-005) was released for Drupal 7. Any Drupal site running Drupal 7.31 or lower needs to update to 7.32 or apply the patch immediately. Here are some tips to get your Drupal 7 site updated today!
Building multilingual websites in Drupal can be a daunting exercise. Understanding how each module works and how which set of configuration it provides is a task in and of itself.
Not everyone wants or needs to install yet another module, and due to the caveats we mentioned about Localization client, it is still a good idea to be familiar with all of your options. In this lesson, we'll review the Locale module translation process, then enable Localization Client and start translating some text!
Additional resources
Localization Client project
Using Drupal, 2nd edition
Using Drupal source code
There are two main areas of translation for your Drupal site: the user interface and the content. The user interface text is mostly provided by the software, stored in the code itself. This is sometimes referred to as "hard-coded." While content is generated by users of the site, and stored in the database. Drupal core comes with the Locale module, which works with the user interface text and gives you a nice set of tools that lets you import existing translations, create or edit your own, or export your site’s translations for use on other sites. In this lesson we'll take a tour of the Locale module and discuss translation files, translating strings, language switching, and how to get a localized installation.
Additional resources
The first step to using any of Drupal’s multilingual features is installing a translation, so that Drupal has more than one language to choose from. As mentioned previously, you can use a localized distribution so that you install your language during the site installation process. Alternatively, you can easily add a language after you have installed the site by using the “Localization update” module. In this lesson we'll get the right pieces in place and get two different languages installed on the site.
Additional resources
Drupal Translations on localize.drupal.org
Using Drupal, 2nd edition
Using Drupal source code
With several language translations installed on our site, we need to make a choice about how and when Drupal will use our new languages. In this lesson, we'll review the Locale module configuration to make sure it is performing the way we want it to, by setting language detection and selection, and then enabling our language switcher.