You are on page 1of 19

Drupal 6.

x ­ Plantillas
1
DRUPAL.CAT presenta:
DRUPAL 6.x – PLANTILLAS
2ª parte: Los ficheros “Template” (TPL)

Por: Isaac el cec
 (alias tenomar@drupal.cat)

No os perdáis las próximas sesiones...
Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
2

Ficheros “template”
● “template.php” ­ definición de nuevas 
funciones y variables o sobre­escritura de las del 
núcleo (solo para usos avanzados). Permite añadir 
funcionalidades a la plantilla.
● “page.tpl.php” ­ definición general de la 
estructura de la página. Empezaremos por este ;­)
● “node.tpl.php” ­ como se muestran los nodos.
● Otros ficheros “*.tpl.php”
2
Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
3

Ficheros “*.tpl.php”
● xHTML y PHP interpretado por el motor de 
plantillas y que determinan el modo en que se 
visualizan determinados elementos . . .
● El motor de plantillas pone a disposición de estos 
ficheros una serie de variables (que veremos luego).
● Existen modelos en las carpetas de los módulos. 
Por ejemplo, en [modules/system/] hay, entre 
otros, “page.tpl.php” y “block.tpl.php”. Y 
en [modules/node/] hay “node.tpl.php”
Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas

Otros ficheros (opcionales) 
4

“*.tpl.php” . . .
● block.tpl.php define como se muestran los 
boques.
● comment.tpl.php define como se muestran los 
comentarios.
● box.tpl.php define como se muestran las cajas.
● Aviso: No confundir “box.tpl.php” con “block.tpl.php”

 
Ver muchos más en: http://drupal.org/node/190815

Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
5

Registro de la Plantilla !!!
Hay que renovar el registro de la plantilla 
(“theme”) siempre que se realice alguna de las 
siguientes acciones:
– Añadir o quitar (¿variables?) funciones en el fichero 
“template.php” (Nota: al modificar una función 
existente, no es necesario renovar el registro).
– Añadir o quitar ficheros "*.tpl.php" (Nota: al 
modificar uno de estos ficheros, no es necesario 
renovar el registro de la plantilla).

Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas

¿Como renovar el 
6

Registro de la Plantilla? . . .
● Pulsando el botón [Clear] localizado en 
[ Admin > Site Config > Peformance ]
● Con el bloque “devel” activado (módulo 
“devel”), pulsar la opción [“Empty cache”].
● (Para desarrolladores PHP: Con la función API 
“drupal_rebuild_theme_registry”)

Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas

Variables disponibles en todos 
7

los ficheros “*.tpl.php” . . .
$id – Contador de veces que se utiliza la plantilla.
$zebra – Biestable que cambia cada vez que la plantilla es invocada. Valor 
“odd” o “even”
$directory – Camino relativo a la carpeta de la plantilla 
(“sites/all/themes/...”)
$is_admin – Booleano. Cierto si el usuario es el administrador.
$is_front – Booleano. Cierto si es la primera página (“front”).
$logged_in – Booleano. Cierto si el usuario está autentificado.
$db_is_active – Booleano. Cierto si la BB DD es accesible.
$user – Objeto con datos del usuario actual. Potencialmente peligroso: tratar 
con la función check­paint()
Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
8
Análisis de
page.tpl.php <­> style.css
● Dos ficheros íntimamente relacionados que definen 
la plantilla de presentación general.
● page.tpl.php define el contenido de cada zona 
(región)
● style.css define la posición, tamaño y formato 
de cada elemento. 

Aviso: En la segunda parte se estudiaran los ficheros “tpl”. De nada

Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
9 V. en “page.tpl.php” (I)
Page metadata:
    $language: (object) $language­>language contains its textual representation. $language­>dir contains 
the language direction. It will either be 'ltr' or 'rtl'.
    $head_title: A modified version of the page title, for use in the TITLE tag.
    $head: Markup for the HEAD section (including meta tags, keyword tags, and so on).
    $styles: Style tags necessary to import all CSS files for the page.
    $scripts: Script tags necessary to load the JavaScript files and settings for the page.
    $body_classes: A set of CSS classes for the BODY tag. This contains flags indicating the current layout 
(multiple columns, single column), the current path, whether the user is logged in, and so on. 

Site identity:
    $front_page: The URL of the front page. Use this instead of $base_path, when linking to the front 
page. This includes the language domain or prefix.
    $logo: The path to the logo image, as defined in theme configuration.
    $site_name: The name of the site, empty when display has been disabled in theme settings.
    $site_slogan: The slogan of the site, empty when display has been disabled in theme settings.
    $mission: The text of the site mission, empty when display has been disabled in theme settings. 

Extraido de: http://api.drupal.org/api/file/modules/system/page.tpl.php

Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
Navigation:
10 V. en “page.tpl.php” (II)
     $search_box: HTML to display the search box, empty if search has been disabled.
     $primary_links (array): An array containing primary navigation links for the site.
     $secondary_links (array): An array containing secondary navigation links for the site. 

Page content (in order of occurrance in the default page.tpl.php):
     $left: The HTML for the left sidebar. 
     $breadcrumb: The breadcrumb trail for the current page.
     $title: The page title, for use in the actual HTML content.
     $help: Dynamic help text, mostly for admin pages.
     $messages: HTML for status and error messages. Should be displayed prominently.
     $tabs: Tabs linking to any sub­pages beneath the current page (e.g., the view and edit tabs when 
displaying a node). 
     $content: The main content of the current Drupal page. 
     $right: The HTML for the right sidebar. 

Footer/closing data:
     $feed_icons: A string of all feed icons for the current page.
     $footer_message: The footer message as defined in the admin settings.
     $footer : The footer region.
     $closure: Final closing markup from any modules that have altered the page. This variable should 
always be output last, after all other dynamic content
Extraido de: http://api.drupal.org/api/file/modules/system/page.tpl.php
Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
11
Fichero “page.tpl.php” (I)
<!DOCTYPE html PUBLIC "­//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1­strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
xml:lang="<?php print $language­>language ?>" 
lang="<?php print $language­>language ?>" 
dir="<?php print $language­>dir ?>">
<head> Variables
<title><?php print $head_title ?></title>
<?php print $head ?>
<?php print $styles ?> Función definida en
<?php print $scripts ?> template.php
<!­­[if lt IE 7]>
<?php print phptemplate_get_ie_styles(); ?>
<![endif]­­>
<script type="text/javascript">
<?php /* Needed to avoid Flash of Unstyled Content in IE*/ ?> 
</script>
</head>

<body>
. . . Continua . . .
Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
12 “page.tpl.php” (II)
. . .
<body class="<?php print $body_classes; ?>">
<div id="page">
<div id="header"> body_casses !!!
<div id="logo­title"> Clases (CSS)
<?php if (!empty($logo)): ?>
<a href="<?php print $front_page; ?>" 
title="<?php print t('Home'); ?>" 
rel="home" 
Textos !!! id="logo">
<img src="<?php print $logo; ?>" 
alt="<?php print t('Home'); ?>" />
Identificadores </a>
 (CSS) <?php endif; ?>
Variables
<div id="name­and­slogan">
<?php if (!empty($site_name)): ?>
<h1 id="site­name">
<a href="<?php print $front_page ?>" 
Ver resto del fichero en title="<?php print t('Home'); ?>" 
modules/system/page.tpl.php  rel="home">
Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
13

Clases en “$body classes”
● [ front / not­front ]
● [ logged­in / not­logged­in ]
● [ node­type­page / node­type­xxx / ...]
● [ no­sidebars / one­sidebar sidebar­left /     
ono­sidebar sidebar­right / two­sidebars ]
● Nota: Esto permite múltiples posibilidades a nivel de CSS:
– h1.front  { font­size: 2.0em; }
– h1.not­front { font­size: 1.5em; } . . .

Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
14

Fichero “style.css”
● Hoja de estilos por defecto, si no se especifica 
nada en el fichero “.info” de la plantilla. 
● Otras hojas de estilo: declararlas en “.info” 
(atención al orden de declaración) o cargarlas 
desde “style.css”
● En el fichero “zen/STARTERKIT/drupal6­
reference.css” (de la plantilla ZEN) están 
listadas todas las etiquetas y clases definidas por 
los módulos del núcleo del Drupal 6.x
Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
15 V. en “node.tpl.php” (I)
Available variables:
    $title: the (sanitized) title of the node.
    $content: Node body or teaser depending on $teaser flag.
    $picture: The authors picture of the node output from theme_user_picture().
    $date: Formatted creation date (use $created to reformat with format_date()).
    $links: Themed links like "Read more", "Add new comment", etc. output from theme_links().
    $name: Themed username of node author output from theme_user().
    $node_url: Direct url of the current node.
    $terms: the themed list of taxonomy term links output from theme_links().
    $submitted: themed submission information output from theme_node_submitted(). 

    $node: Full node object. Contains data that may not be safe.
    $type: Node type, i.e. story, page, blog, etc.
    $comment_count: Number of comments attached to the node.
    $uid: User ID of the node author.
    $created: Time the node was published formatted in Unix timestamp.
    $zebra: Outputs either "even" or "odd". Useful for zebra striping in teaser listings.
    $id: Position of the node. Increments each time it's output.
Extraido de: http://api.drupal.org/api/file/modules/node/node.tpl.php/6
Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
16 V. en “node.tpl.php” (II)
Node status variables:

    $teaser: Flag for the teaser state.
    $page: Flag for the full page state.
    $promote: Flag for front page promotion state.
    $sticky: Flags for sticky post setting.
    $status: Flag for published status.
    $comment: State of comment settings for the node.
    $readmore: Flags true if the teaser content of the node cannot hold the main body content.
    $is_front: Flags true when presented in the front page.
    $logged_in: Flags true when the current user is a logged­in member.
    $is_admin: Flags true when the current user is an administrator. a

Extraido de: http://api.drupal.org/api/file/modules/node/node.tpl.php/6

Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
17
Fichero “node.tpl.php”
<div id="node­<?php print $node­>nid; ?>" 
class="node<?php if ($sticky) { print ' sticky'; } ?>
<?php if (!$status) {print ' node­unpublished';} ?> clear­block">
<?php print $picture ?>
<?php if (!$page): ?> Variables
<h2> <a href="<?php print $node_url ?>" 
title="<?php print $title ?>"> 
<?php print $title ?> </a> </h2>
<?php endif; ?>
<div class="meta"> Etiquetas CSS
<?php if ($submitted): ?>
<span class="submitted"> <?php print $submitted ?> </span>
<?php endif; ?>
<?php if ($terms): ?>
<div class="terms terms­inline"><?php print $terms ?></div>
<?php endif;?>
</div>
<div class="content"> <?php print $content ?> </div>
<?php print $links; ?>
</div>

Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas

Otros ficheros “*tpl.php” ...
18

a discreción !!!

Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.
Drupal 6.x ­ Plantillas
19

Fin de esta PARTE...

Gracias por la
atención prestada

¿Preguntas? . . .

Autor: isaac.el.cec@gmail.com – Bajo licencia Creative Common 3.0 – Reconocer Autor y Compartir Igual.

You might also like