To do the job, supposing that you are using D6, so, you can insert some variables to your template like this :
Second thing, we define the theme hook for our page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php // We define here a new theme file for your your page // Your theme file must be located in your module's folder // you can use a subfolder to group all your module's theme files // E.g : themes/my-module-theme.tpl.php // Note that in theme files, we change _ by - function my_module_theme() { return array( 'my_module_theme' => array( // Keep that name in your mind 'template' => 'my_module_theme', 'arguments' => array( 'my_var' => NULL, 'my_var2' => NULL, ), ) ); } ?> |
Now we can create a file "my-module-theme.tpl.php" in the root folder of our module, and paste something like "foo AND bar!" Back to our my_module.module, the callback must be something like :
1 2 3 4 5 6 7 8 |
<?php function my_module_mypage($x, $y) { // $x and $y are optionnal, so this is the first manner // to inject variables into your theme's file $output = theme("my_module_theme", $x, $y); return $output; } ?> |
Also you can use preprocess hook to insert variables
1 2 3 4 5 6 7 8 9 10 11 |
<?php // The hook must be named like this : template_preprocess_NAME_OF_THEME_FILE // where NAME_OF_THEME_FILE is the name that you kept in your mind ;) function template_preprocess_my_module_theme(&$variables) { // Do some job $var1 = 'Foobar'; // So in "my-module-theme.tpl.php", $my_var1 will print Foobar $variables['my_var1'] = $var1; } ?> |
That's all folks!
’)