please let me know what the following lines of code mean - drupal

What is mean by the following code, I found it in the comment module (drupal 6)
return theme('box', $title, drupal_get_form('comment_form', $edit, $title));
I have used this theme function before, but I had defined some themes under hook_theme(). but I didn't see any themes defined as 'box', also I found same theme 'table'
Could you please show some urls where it explains about these things
Thank you very much

With the Drupal theme system you can overwrite theme functions. So if you don't like the markup that theme_box makes, you can make my_theme_box instead and Drupal will use that function instead. The thing is in order for this to work you can't call theme_box directly. If you do that you in your module your theme can't alter the output. Instead you call theme('box', ...) this will tell Drupal that's it's the box theming function you want. It will the find out which function to call based on what's available. So if your theme doesn't have my_theme_box defined theme_box will be used instead.

Have you already read Drupal API Reference? There's an explanation about themes, too.

Related

Best way to embed js/jquery into a Display Suite layout template file?

I'm themeing a drupal site using display suite - all current versions. As you may realise, in drupal there are many ways to achieve an equivalent result. I have created a number of custom layouts in display suite. Now I want to add jquery to some of those layouts so that the jquery only loads when those layouts are displayed (as opposed to making the same jquery file load on every page in the theme).
Sure I can use something like drupal_add_js() or $form#attached etc. But what's wrong with adding a tag in my template file? What is the 'Display Suite method' for doing this - I have to believe they (Display Suite team) have already thought of this...
Thanks.
One way to accomplish this is through hook_ds_pre_render_alter(), e.g:
/**
* Implements hook_ds_pre_render_alter();
* Add custom JavaScript.
*/
function MYMODULE_ds_pre_render_alter(&$layout_render_array, $context, &$vars) {
if($vars['type'] === 'MY_NODE_TYPE' && $vars['view_mode'] === 'full') {
drupal_add_js(drupal_get_path('module', 'MYMODULE') . '/js/my_js_file.js');
}
}
Adding the JavaScript through #attached would be preferable as it seems cleaner and is more in line with the approach taken in Drupal 8, however I couldn't find a way to do this. Display Suite seems to override hook_node_view() and adding #attached in to an implementation of ds_pre_render_alter() didn't get me anywhere. Declaring a .js file in a custom DS .inc layout file is also unfortunately not supported.
Implementing drupal_add_js() directly in a .tpl.php template file might not work as expected and seems to not be 'best practice' (see https://drupal.stackexchange.com/questions/20520/drupal-add-js-in-html-template-file).
Interestingly though in Drupal 8 drupal_add_js() is being removed entirely in favour of #attached and it will be possible to add JavaScript directly in templates, see https://www.drupal.org/theme-guide/8/assets).

Change theme for node add page in Drupal 7

I tried using hook_custom_theme to change the theme for the node add page for a specific content type, like this, without success:
function mymodule_custom_theme() {
if (current_path() == 'node/add/mytype')
return 'anothertheme';
}
I know the function is running, and I know the comparison is returning TRUE. Why is it not working?
I think you are not writing the theme name correctly.
But there is a module which could do this work for you: https://drupal.org/project/themekey
Regards.
1) Do you use the correct machine name for the theme?
2) Are you sure that there are not other modules to override this later?
3) Is the page cached? If so this may not work properly.
Same question and discussion here: https://drupal.stackexchange.com/questions/812/how-do-i-change-a-theme-based-on-the-url
Useful modules:Page Theme, Context, ThemeKey.

Accessing html.tpl.php variables from page.tpl.php

Greeting,
I am stuck with accessing $scripts variable of html.tpl.php in page.tpl.php, how to access the variable?
I am using Drupal 7
Please Help.
Thanks in Advance.
In order to alter the page's scripts, take a look at implementing hook_js_alter() in a custom module. That will allow you to perform the necessary alterations without messing with the rendered output. Further info here.
You must send explicity the variable you want to the template you want, template variables are template specific, there's no inheritance or another clean way.
The clean way is send what you need to specific template or implement a hook if it exists and does what you want.
Finally, in this case, I think you have to decide which files are loaded when hook_js_alter is called as suggested jamix.

preprocess_views_view not getting called

Drupal 7,
Views,
Bootstrap theme sub theme in use
I have a views-view-table.tpl.php file in my sub theme and I am trying to preprocess some of the variables sent to this tpl. I created a function bootstrap_preprocess_views_view(&$vars) in my template.php and it is not getting called when I visit one of my views pages. Why would this be? Other preprocess functions are getting called from the same template file. I have tried flushing the cache.
function bootstrap_preprocess_views_view(&$vars) {
dsm($vars);
dsm("aaaa");
die;
}
Adam,
I'm assume you've tried all the regular things like clearing your cache, etc before expecting to see the change.
If yes, perhaps this old Drupal issue may be affecting your function: http://drupal.org/node/258089 (since your syntax looks fine).
Do you actually have a corresponding template file in your sub-theme? If you place one in there (even just by copying and pasting the default one from the views module), does it solve your issue?
Let us know!

How does one inject variables into page templates from a custom Drupal module?

We've created a custom module for organizing and publishing our newsletter content.
The issue I'm running into now -- and I'm new to theming and Drupal module development, so it could just be a knowledge issue as opposed to a Drupal issue -- is how to get each newsletter themed.
At this point the URL structure of our newsletter will be:
/newsletters/{newsletter-name}/{edition-name}/{issue-date} which means that we can create template files in our theme using filenames like page-newsletters-{newsletter-name}-{edition-name}.tpl.php, which is great. The one issue I'm running into is that all of the content comes through in the $content variable of the theme. I'd like to have it come through as different variables (so that I can, inside the theme, place certain content in certain areas.)
Is there a proper way for doing this?
Edit: To answer some questions: The issue is a node (there are issue, edition and newsletter nodes) and the path is being set using hook_menu with wildcards and a router.
The best answer I could find was to add a check inside of phptemplate_preprocess_page to send the vars back to the module and have them be updated.
Like so:
function phptemplate_preprocess_page(&$vars) {
if (module_exists('test_module')) {
_test_module_injector($vars);
}
}
then in my test_module.module file I created this function:
function _test_module_injector(&$vars) {
$vars[] = call_to_other_functions_to_load_vars();
}
It seemed to work. I wish there was a way to do this without having to touch the theme's template.php file, but otherwise this works well.
If there were better documentation for template preprocess functions, Drupal would be a lot more accessible - as it is, you need to piece together the information from a lot of different explanations. One place to start is here:
http://drupal.org/node/223430
but if you take the time to work through the tutorial below, you'll find you can do most things:
http://11heavens.com/theming-the-contact-form-in-Drupal-6
This is an old post, and the OP's issues seems to have been solved.
However, just for others finding this through Google (or otherwise):
Install the 'Devel' module: http://drupal.org/project/devel
Also the 'Devel Themer' module: http://drupal.org/project/devel_themer
Use Devel Themer to go through the $content variable and find what you need to pull out.
There are a bunch of Devel/Themer docs/tuts out there, but its usage is pretty straightforward. Note, though, that some stuff in there will need to be sanitized before printing in the theme.
The suggestion to show the node as a View and then modifying the view templates sounds pretty crazy, though it'll work.

Resources