This is a very basic question but I need to know the answer - Im not used to database programming yet.

Here's some code from a page.tpl.php file -

<head>
  <title><?php print $head_title; ?></title>
  <?php print $head; ?>
  <?php print $styles; ?>
  <?php print $scripts; ?>
  <script type="text/javascript"><?php /* Needed to avoid Flash of Unstyled Content in IE */ ?> </script>
</head>

Where are the values such as %head_title, $styles, etc....coming from? I mean obviously they are being pulled from the database somewhere and placed in those variables but page.tl.php doesn't declare them and it doesn't include any other .php files so how are these variables available to page.tpl.php?
Cheers.

Comments

Tiburón’s picture

Yes the content of those variables originate from the database but on the way to the theme layer the data wil be processed in various ways in order to prepared for output on the page.

Have a look at the Theming guide. It will give you an overview of the process and the specifics on how to build you own theme from scratch or modify an exiting.

Regards,

Christian Larsen

ltwinner’s picture

ok cool, i understand it a bit better now after doing some research. I have another kind of related question now as I want to fully understand what drupal is doing behind the scenes. I have the following line of code in my page.tpl.php file -

print theme('links', $primary_links, array('class' => 'Links primary-links'));

Could someone tell me exactly what is happening here? What are each of three arguments: 'link', $primary_links, and array('class' => 'Links primary-links') and what is the function doing with them?

And what is the => operator doing, I am unfamiliar with it.

Cheers.

Tiburón’s picture

The statement is a call to Drupals theme layer invoking the theme_links () function. Exactly which one that get called depends on where they are defined (this is explained in the theme guide somewhere). They can be in core, modules, and even in the template.php of your theme. The default declaration is theme_links() but in your theme you could have your own which would be called instead. It should then be called yourthemename_links().

Here is a good tip: Whenever you encounter a function name in Drupal and you wonder what it is for have a look at api.drupal.org.

In this particular case you would look at theme_links.

It takes two arguments an array of links (key pair of text and url) and an optional array of attributes for the unordered list HTML element (again key pairs of attribute name and content).

In the statement you have listed the list of primary_links are passed on to theme_links and in the returned HTML snippet the unordered list element gets the class attribute with the content of "Links primary-links" like this <ul class="Links primary-links">

The array('class' => 'Links primary-links') is PHP for delcaring an array of key pairs that map a key to data. That is array( key => data). For the detail have a look at the PHP documentation on arrays.

Also read the rest of the Drupal documentation for more insight.

Regards,

Christian Larsen

ltwinner’s picture

ok cool, thanks for the help man.

Tiburón’s picture

No problem :-)

... and welcome on board the fine ship Drupal

Regards,

Christian Larsen