Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Theme and variable management

From: Simplified Drupal Sites with Drush

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.

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.

Show transcript

This video is part of

Image for Simplified Drupal Sites with Drush
Simplified Drupal Sites with Drush

18 video lessons · 4145 viewers

Jon Peck
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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.

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
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?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

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:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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.