I have a module witch generates a custom page:
function my_module_basket_menu() {
$items["my-basket"] = array(
"title"=>"My basket",
"page callback" => "_my_basket_page",
"access arguments" => array("access my_module_basket content"),
);
return $items;
}
function my_module_basket_theme($existing, $type, $theme, $path) {
return array(
'my_module_basket_page' => array(
'template' =>"my_module_basket_page",
'render element' => 'page',
'arguments' => array("listeProducts" => NULL, "key" => $key),
),
);
}
function my_module_basket_theme_registry_alter(&$theme_registry) {
$hooks = array('page');
foreach ($hooks as $h) {
// Add the module path on top in the array of paths
array_unshift($theme_registry[$h]['theme paths'], drupal_get_path('module', 'my_module_basket'));
}
}
function _my_basket_page() {
// ...some treatment
return theme("my_module_basket_page", $liste_produits, $key);
}
All works fine, but the problems start here: I want also to have a specific page.tpl, for example page_my_basket.tpl.php
.
I tried to create a function my_module_basket_preprocess_page
and change the theme there but the URL path I catch is the node of the page 404. Impossible to catch "my-basket". Any ideas? A different suggestion on how i can make it work?
EDIT
As suggested, i changed the name of my registry_alter function. From here when i look at the url (with a dsm()), i catch the good one, not the 404. So that part is ok.
So now i have to theme two page tpl, one for the page create in the module and a second one to replace the page.tpl.php The problem is this second page i add a function preprocess in my module :
function my_module_basket_preprocess_page(&$variables, $hook){
$alias = drupal_get_path_alias($_GET['q']);
if ($alias == "my-basket") {
$variables['template_files'][] = 'page_my_basket';
}
}
In my hook_theme function, i have that :
function oxo_wedze_basket_theme($existing, $type, $theme, $path){
return array(
'my_module_basket_page' => array(
'template' =>"my_module_basket_page",
'arguments' => array("listeProducts" => NULL, "key" => $key)
),
'page-my-basket' => array(
'template' =>"page_my_basket",
'render element' => 'page'
),
);
}
And that don't work, i still get the standard page.tpl.php
hook_theme_registry_alter()
is not correct, it must start with your module name:my_module_basket_theme_registry_alter()
. Please update your question after fixing this error and testing again.hook_theme
implementation check your return array. You are using dashes instead of underscores.page-my-basket
should be corrected aspage_my_basket
.