Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now

Theme and variable management


From:

Simplified Drupal Sites with Drush

with Jon Peck

Video: Theme and variable management

Downloading and enabling themes is the same as downloading and enabling modules, to a point. I will describe the differences in how to mitigate them. First, let's list the themes that are currently available, drush pml --type=theme. There are four themes and two of them are enabled. However, Drupal themes have some differences for modules, in particular there are default themes which are used unless otherwise specified and admin themes which are used on admin pages only.
please wait ...
Watch the Online Video Course Simplified Drupal Sites with Drush
1h 22m Intermediate Dec 06, 2012

Viewers: in countries Watching now:

Manage your Drupal sites even more efficiently with Drush, the shell interface for managing and scripting Drupal site development. In this quick course, author Jon Peck describes what Drush is, how to install it, and how to use it effectively for everyday—and exceptional—tasks.

The course describes how to manage users, download and install modules and themes, archive and restore your entire site, and employ site variables for fast, full control over your Drupal sites. Plus, discover how to script an entire Drupal site installation with and without site profiles.

Topics include:
  • What is Drush?
  • Installing the prerequisite files
  • Installing Drush with PEAR, manually, and just for Windows
  • Installing Drupal sites
  • Managing themes
  • Controlling user access
  • Controlling cache and cron
  • Reading logs
  • Updating modules
Subjects:
Developer Web
Software:
Drupal Drush
Author:
Jon Peck

Theme and variable management

Downloading and enabling themes is the same as downloading and enabling modules, to a point. I will describe the differences in how to mitigate them. First, let's list the themes that are currently available, drush pml --type=theme. There are four themes and two of them are enabled. However, Drupal themes have some differences for modules, in particular there are default themes which are used unless otherwise specified and admin themes which are used on admin pages only.

The project manage list doesn't show this information. These settings are stored as Drupel site variables. In Drupal development, there are two functions, variable_get and variable_set, that are used to retrieve and save settings and other one-off types of information from hardcoded settings in settings.php and from the database. Drush provides an interface to these site variables with a variable_get and variable_set commands aliased as vget and vset. I will start with variable_get, help vget.

vget takes one argument, the partial or complete name of the variable. If ommited, vget will return all variables. The next bit isn't explicitly documented so I will demonstrate it for you. The default theme is saved in a variable named theme_default. Let's get the value of theme_default now: drush vget theme_default. Currently the default theme is bartik. I am going to switch to the garland theme which is included in core but not enabled.

First, I'll enable garland using project manage command enable garland, drush -y en garland. Then, I will set the variable using the vset command, drush help vset. Variable set has a lot of options, but in the simplest mode it can just set a given value to a particular named variable name. So in this case, drush vset theme_default, to "garland". Theme default is now set to garland.

Verify this by using vget again: drush vget theme_default, and it's set to garland. Switch back to the browser and go to the homepage and reload, make sure that you can see the difference. As the administrative theme is distinct from the theme default there is a different variable, going back to the terminal use vget again, but this time on the variable admin_theme, drush vget admin_theme.

This time two variables will be shown, by default vget searches for variables that contain the search term. To be more specific pass an additional option called Exact, which will only match the exact variable: drush vget admin_theme --exact. This is functional but what if I wanted to change to a different admin theme such as Rubik. Three steps are required, first, download the Rubik theme which also has a soft dependency with the Tao theme.

Usually, dependencies are auto enabled, but in this case it hasn't been explicitly defined by the theme author so it will need to be explicitly downloaded and enabled: drush dl rubik tao. Next, enable the Rubik in Tao themes. So, drush -y en rubik tao. Finally, set Rubik as the admin theme. If there was one exact match, variable set will just set that one variable and will not set the additional variables.

If there is not an exact match, like when a variable has never been set, then the exact option will allow the variable to be set. So in this case I'll just type, drush vset admin_theme rubik. Return to the browser and navigate to the Configuration page to see the difference, which is very striking. I'm going to put the admin theme now back to default: drush reset admin_theme seven.

Going back to the browser and refreshing. And it's back to normal. The vget command can be very useful for tracking changes over time on UNIX like systems. On the configuration page go to site information. Now we will switch back to the terminal for just a moment. By default, variable get will return all variables. I will write every variable in this site to a flat file before I make a change then do a second file and compare the differences to see what was written. This can be useful when storing variables and code, either in settings.php or when explicitly setting a variable in a hook update.

I'm going to give the command "drush vget" and write the output to a file named "before". Next, go to the browser and set the site name to Drush and the slogan to "a command line shell and scripting interface for Drupal". Save the changes then navigate to the site home page. The new site name and slogan are shown. Return to the terminal then dump the variables into a file named "after": drush vget to after.

Finally, use the diff command to show the difference between the two files: diff before after. There are two symbols the greater than symbol indicates that something was written and the less than symbol indicates that something is removed. With this view, I can see that not only were the variables, site name and site slogan, written but so are some other values as well. If I wanted to hardcode these variables in the settings.php I can use another feature of variable get, the pipe option. In this context, I will render the variables as a line of PHP: drush vget site_name --pipe.

And, drush vget site slogan --pipe. I can take these two lines and copy them into settings.php, renaming the dollar $variables to dollar sign $conf to force the site name and slogan to be whatever I specified. For more information on defining variables in the site's settings.php conf array, see drupal.org/node/1525472.

I have demonstrated how to enable, disable, and set the site default and admin team without using the site interface. This can be extremely useful, especially when a mistake was made when developing a theme and a failsafe is needed. In the next segment, I will demonstrate how to manage users, including creating and disabling users, then changing passwords.

There are currently no FAQs about Simplified Drupal Sites with Drush.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Simplified Drupal Sites with Drush.

Return to your organization's learning portal to continue training, or close this page.


OK

Upgrade to View Courses Offline

login

With our new Desktop App, Annual Premium Members can download courses for Internet-free viewing.

Upgrade Now

After upgrading, download Desktop App Here.

Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Start your FREE 10-day trial

Begin learning software, business, and creative skills—anytime,
anywhere—with video instruction from recognized industry experts.
lynda.com provides
Unlimited access to over 4,000 courses—more than 100,000 video tutorials
Expert-led instruction
On-the-go learning. Watch from your computer, tablet, or mobile device. Switch back and forth as you choose.
Start Your FREE Trial Now
 

A trusted source for knowledge.

 

We provide training to more than 4 million people, and our members tell us that lynda.com helps them stay ahead of software updates, pick up brand-new skills, switch careers, land promotions, and explore new hobbies. What can we help you do?

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.