Gentlemen,
Documentation says hook_theme "return[s] an array of arrays. The key to each sub-array is the internal name of the hook, and the array contains info about the hook".
Now, I'm coding a module that provides a custom content type (a chess game) and my question is: can I use this to provide multiple templates for my custom content type? For example, I'd like to show by default a list with info about the chess game and a MENU_LOCAL_TASK that when clicked, shows the chessboard. I was thinking in doing something like:
function partida5_theme() {
return array
(
'partida5_info' => array
(
'template' => 'partida5_info',
'arguments' => array
(
'titulo' => NULL,
'descripcion_partida' => NULL,
'jugador_blancas' => NULL,
'jugador_negras' => NULL,
'tiempo_por_participante' => NULL,
'turno_de' => NULL,
),
),
'partida5_juego' => array
(
'template' => 'partida5_juego',
'arguments' => array
(
'titulo' => NULL,
'tiempo_por_participante' => NULL,
'turno_de' => NULL,
'jugador_blancas_uid' => NULL,
'jugador_negras_uid' => NULL,
'estado_tablero' => NULL,
),
),
);
}
partida5_info being the info template and partida5_juego being the chessboard's template.
Is this the right way? And how do I select a specific template for each case?
Thanks in advance,
Léster
Comments
Solved, in case someone was
Solved, in case someone was wondering.
1: Declare all the templates you'll need in hook_theme, like this:
2: Create all the template files you'll need. For example, were I to implement the 3 themes I declared in hook_theme, I have to create 3 files: template_1.tpl.php, template_2.tpl.php, and template_3.tpl.php . Note that the filename for each template is the declared 'template' name, plus .tpl.php .
3: Each time you need to call a specific template, use the return theme() magic to do it. For example, when I want to use the first template, do it like this:
And it's done.