I'm working in a hook menu for a custom route, like this:
function mymodule_menu() {
$items = [];
$items['myroute/%'] = array(
'page callback' => 'my_callback',
'page arguments' => array(1),
'access arguments' => array('access content'),
);
return $items;
}
In the theme_hook, i added a new template feature, like this:
function mymodule_theme($existing, $type, $theme, $path) {
$default = array(
'path' => drupal_get_path('module', 'mymodule') . '/templates',
'variables' => array(),
);
return array(
'product_tile' => array_merge($default, array(
'template' => 'product-tile',
)),
);
}
I created a template file called 'product-tile.tpl.php', wich is working fine for all situations and is a partial template.
In the callback function, i need to return a specific .tpl.php template, like this:
function my_callback($parameter) {
$template_data = 'lorem ipsum';
$output = theme('product_tile', array('content' => $template_data ));
echo ($output);
}
The point is: the 'theme()' function is taking too long to render data and it renders not only the template, but the whole html structure, wich is not needed and is not part oof the template.
Ex: template is:
<div id="my structure></div>
But when i get my response to '/myroute/myparameter, instead of printing my template, it prints all html structure like this:
<html>
<body>......lots of stuff here +js +css + all drupal stuff
<div id="my structure></div>
</body>
</html>
And takes a lot of time to print (like 10s or more).
I tried to cache it by using cache_get and cache_set, but strange things are happening, like random empty responses.
Does anyone know a more performatic way to print a partial template in a hook menu in drupal 7? i's terribly slow this way.
Thanks in advance