views:

728

answers:

7

I am trying to migrate my site to Drupal and I am confused about themes and templates. The look and feel of the pages in my current site are completely controlled by template files and CSS. How does it work in Drupal?

+3  A: 

In drupal, a theme handles the appearance of the site and a template handles how your content is rendered.

Think of it like this: the template is used to render the content, then the theme is applied on that content.

Edit: So, your css files live with the theme in drupal, and have nothing to do with the templates.

BenB
+3  A: 

In Drupal, a "theme" is just a special type of plugin that bundles together any number of templates (to control how a given piece of data gets rendered to HTML), CSS, JS files, images, and so on.

So, there is a single "template" for your oveevral page markup, a single "template" for how a sidebar block is rendered as HTML, and so on. All of them, bundled together and named, are referred to as a theme.

Eaton
A: 

I'm confused...

The first answer says that templates and themes have nothing to do with each other, while the second one says themes are just collections of answers.

Which one is right?

Eaton's and canen's answers are more accurate, especially before BenBruscella edited his answer.
FGM
+1  A: 

A theme is made up of a collection of template files. block.tpl.php, node.tpl.php, page.tpl.php are all template files which when combined with your CSS, JS and images produces a theme. In addition a themes can be inherited. A theme can be created with just CSS and no additional template files by inheriting from an existing theme, in which case the template files from the parent theme are used.

Another way to look at it is a theme is what you see and the template files are responsible for generating the markup.

I hope this makes it a little bit clearer.

canen
A: 

Look at it this way: It's possible to create a theme that has no templates. Such a theme would have CSS files that override drupal's default CSS files. Using such a theme would create a website that looks almost exactly like Drupal's default site, except it would have different colors, fonts and so on.

But if you want to change the positions of items on the page, what kinds of items are on the page and so on, you have to override the default templates by adding some of your own to your theme. These new templates let you alter what information Drupal displays and what kind of HTML Drupal will use to display it.

For example, say I want to clone StackOverflow, but I want to do it with Drupal. First thing I would do is create a new content type (call it a "question") that is just like a story but has extra fields to track voting and so on. Drupal's default templates won't know about these extra fields, so they won't display them.

So, what I do is I go into my theme and I add a new node.tpl.php file. This new template is just like the standard one, except I can add code that says "if this node is of type 'question', insert the voting gadget to the left of the body."

Does this help?

Mike Heinz
A: 

Drupal is having a template based theming system. You can define your own regions in page and can arrange the content according to that . There are some default template file such as page.tpl ,block.tpl ,node.tpl which are displaying different kind of contents . You can write your own template file as needed for eg if you need to alter the display of user registration form or login page you can create a tpl file for that and have to redirect the data to that tpl file. You can add the css or js to these templates using drupals apis. This redirection has to be done in the themes template.php file

Jinesh
A: 

A theme is comprised of css, js, images, and template files. Each theme may include multiple template files.

Additionally, themes can be inherited, and a subtheme's template files could override the template files of its parent theme.