Posted by miiimooo on September 18, 2009 at 12:16pm
Jump to:
| Project: | jTemplate |
| Version: | 6.x-1.0 |
| Component: | Documentation |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
This looks very interesting. I think I've read through all documentation but I can't figure out how to enable it. Where does the frontend go, where the backend?
Thanks
Comments
#1
This is a rough tutorial and leaves some blank spots but i hope you'll be able to figure it out. This module is a "driver" of the jTemplate theming, you need to create your own javascript templates that are located inside modules, once you ahve those template you can use them by utilizing the jTemplate theme function in javascript.
You need to create a custom drupal module like mymodule.module instructions here: http://drupal.org/node/206753
Then in that module you need to create a "hook_menu" (which will be like mymodule_menu ) that will define a path URL that your drupal site will be able to respond to.
In your module you create this function:
/*** Create hook_jtemplate_themes();
*/
function mymodule_jtemplate_themes() {
return array (
'mymodule_theme' => array(
'template' => '{#for index = 1 to $T.limit} {$T.index} {#/for}',
'settings' => array(),
'includes' => array(),
),
);
}
Then in javascript you call the jtemplate with [callback] where callback is "mymodule_theme" in above example.
#2
I think I begin to understand. Thanks for this. Do you happen do have an example theme that you could publish? I still don't see how the code above pulls the theme from the server side/Drupal?
#3
Here is the workflow.
1) You make a javascript call like this: Drupal.theme('jTemplate', 'mymodule_theme', '[#theme-container-parent]');
2) Drupal.theme.jTemplate is defined in jquery-jtemplates-init.js, it makes an ajax call back to the server to this URL jtemplate/callback/mymodule_theme
3) URL above is mapped to function jtemplate_theme_registry($template) (so $template will be "mymodule_theme" in this example).
4) That function executes this code:
<?phpfunction jtemplate_theme_registry($template) {
//cache this later
$templates = module_invoke_all('jtemplate_themes'); // fetch all themes defined inside hook_jtemplate_themes
print drupal_to_js(isset($templates[$template]) ? $templates[$template] : ''); // If requested $template exist, return it's contents. otherwise return empty string if invalid theme was requested.
exit();
}
?>
5) After theme was returned we are using jTemplate's engine to apply the theme to a div element with ID #theme-container-parent
6) after theme was applied to the div element, it is executed.