Adding HTML to Drupal Close?

To add javascript you can use:

drupal_add_js 

And similarly for css:

 drupal_add_css 

But what if I just want to add html at the end of my page. That is, add a div with some text at the end of the page?

+4
source share
9 answers

Many suggestions here work if you want your changes to be theme-based, but if you want it to come from a module, using the block area, page template or prepocess of the page will not reduce it because you are linking the changes to the theme.

From a modular point of view, it is best to use the following parameters:

hook_footer () - http://api.drupal.org/api/function/hook_footer/6 :: my_module_footer () should return an HTML string, which may even be javascript. For instance.

 function my_module_footer(){ return "<script type='text/javascript'>//your script</script>" } 

You can use drupal $ _GET ['q'] to get the URL of the page, and return this condition for the URL of the page.

Otherwise, I sometimes use $ GLOBALS ["_ add_my_footer"] as a boolean and set it at different points in the module, and then in hook_footer (), if true.


drupal_add_js - api.drupal.org/api/drupal/includes--common.inc/function/drupal_add_js/6 :: You can use this to add javascript to the footer by setting the $ scope parameter for the footer - for example

 function my_module_init(){ $script = "your script "; // notice no <script> tags drupal_add_js($script, 'inline', 'footer'); // you can also use this function to grab a .js file } 

Please note that I put this drupal_add_js in hook_init () - I did this because if you do not, the script may get lost when using the Drupal aggressive caching function.

Sorry for the drupal_add_css parameter

there is no $ scope parameter,
+9
source

Since hook_footer did not survive Drupal 6, here is the equivalent function and how to implement it in Drupal 7:

 /** * Implements hook_page_alter(). */ function example_page_alter(&$page) { if (variable_get('dev_query', 0)) { $page['page_bottom']['devel']= array( '#type' => 'markup', '#markup' => '<div style="clear:both;">' . devel_query_table() . '</div>', ); } } 

(From http://preprocess.me/drupal-hookfooter-in-drupal-7 )

+4
source

You can add the following to the template.php theme file:

 function phptemplate_preprocess_page(&$vars) { $vars['closure'] .= 'Add markup here'; }
function phptemplate_preprocess_page(&$vars) { $vars['closure'] .= 'Add markup here'; } 
+3
source

You can write a block to do this, and put the block in closure.

+2
source

Drupal has a hook that you can implement and add any code you want to use in the page footer - hook_footer. See http://api.drupal.org/api/function/hook_footer/6

+2
source

... or maybe not as recommended as other answers, but more direct, you can add html directly to page.tpl.php.

+1
source

Several good suggestions have already been made:

  • Block usage
  • Editing Templates
  • Using the preprocessing function.

The easiest way would be to add a block to be created where you can put your own markup. You can even create a special template for it, so that you will not get your usual drupal block layout, but only what you write in block content.

This should satisfy your needs:

  • You have 100% control over where markup is created (you can define the region in your own).
  • You have 100% control over which markup is created.

Now, if you do not want to use blocks because you do not want site administrators to know about the block, the second best thing:

  • Check the box in the theme settings.
  • In your pre-process page capture, set the boolean variable if the checkbox is checked or not.
  • In your page template, you check the variable, if it is TRUE, you write your markup wherever you want.

This will basically do the same as above, only you have the setting in your theme, instead of adding a block. This will require more work.

You can do almost the same thing in a user module, but it doesn’t make much sense to do this in a module, since it is a pure presentation, and you still depend on your topic.

+1
source

here is a little trick that works in Drupal 6 and 7

  $script = '//--><!]]></script><strong>this is bold html code</strong><script type="text/javascript"><!--//--><![CDATA[//><!--'; drupal_add_js($script, 'inline', 'footer'); 

since it is obvious that you do not want to modify the template files or use any of the other methods suggested above, this should work to add html to the page in the same way as for js and css

+1
source

I do not recommend using a block as its excess to add some elements to the footer. Here is your hook that you can use to add content before the </body> for Drupal 7.

 function hook_page_build(&$page) { $page['page_bottom']['YOUR_MODULE'] = array( '#markup' => '<div> I want to get inserted at the bootom of the page </div>', ); } 
0
source

All Articles