Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think there are two questions here. First, how does a single theme/template get rendered/used/displayed and second, how does the whole site come together. I think the second question has already been answered above, so I'm going to try to explain the first a bit more.</p> <p>First, a module (that's why system.module exists, for all these stuff that only a module can do like implementing hook_menu()) needs to define that a specific theme function/template exists, by declaring it in <a href="http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_theme/7" rel="noreferrer">hook_theme()</a></p> <p>Speaking of that, there are two different things which can be used. A theme function, which is a function prefixed with theme_. Often used for smaller elements of a page wich have more complex logic/PHP like <a href="http://api.drupal.org/api/drupal/includes--theme.inc/function/theme_table/7" rel="noreferrer">theme_table()</a>. And a template, which is a file with the tpl.php like <a href="http://api.drupal.org/api/drupal/modules--system--page.tpl.php/7" rel="noreferrer">page.tpl.php</a></p> <p>To use a theme function/template, you can either call <a href="http://api.drupal.org/api/drupal/includes--theme.inc/function/theme/7" rel="noreferrer">theme()</a> like this:</p> <pre><code>$output = theme('table', array('rows' =&gt; $rows, 'header' =&gt; $header)); </code></pre> <p>Or you can use the new, so called renderable array thing. That is basically an array of data + information which theme to use:</p> <pre><code>$output = array( '#theme' =&gt; 'table', '#rows' =&gt; $rows, '#header' =&gt; $header, ); </code></pre> <p>The second is preferred because it means that it will be themed as late as possible and other modules can change it in hooks. The result will be exactly the same, drupal_render() will then call theme() itself during the final rendering.</p> <p>When theme() is called, it looks up the function/file to use, looks if it has been overriden the used theme, if there are so called template suggestions and then uses them. </p> <p>To override a theme function in a theme, copy it to your template.php file and replace "theme_" with "yourthemename_", if it is a tpl.php file, copy it to your directory.</p> <p>Now, what the final rendering process is doing is basically building up a large $page array, that is a renderable array (Some documentation of that is in <a href="http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_page_alter/7" rel="noreferrer">hook_page_alter()</a> and then call <a href="http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_render/7" rel="noreferrer">drupal_render()</a> on it.</p> <p>The global structure of the page/template hierarchy (which is not hardcoded, but given through whatever is in $page) is something like this:</p> <pre><code>html.php.tpl head.php.tpl page.php.tpl multiple regions multiple blocks </code></pre> <p>Almost everything is a block in Drupal 7, including the actual content, which is typically a node. A theme defines which regions it has and then you can assign blocks to it in the UI.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload