views:

862

answers:

5

To add javascript, you can use:

drupal_add_js

And similar for css:

drupal_add_css

But what if I just want to add html at the end of my page. I.e. Add a div with some text in it at the end of the page?

+1  A: 
This doesnt work.
RD
+2  A: 

You could write a block to do it and put the block in the colsure.

Jeremy French
Doesnt solve my problem.
RD
What did you try, and how did it not solve your problem?
Jeremy French
Agreed with Jeremy. I even used a block to add a SCRIPT SRC tags and it works just fine.
Hendy Irawan
+1  A: 

...or, probably not as recommended as the other answers, but more direct, you can add the html straight to the page.tpl.php file.

lazysoundsystem
I want to do it in such a way, that when I enable a module, it appears in the page, and if I disable the module, it doesnt. So none of these methods would work.
RD
Add a condition to check if the module exists:http://api.drupal.org/?q=api/function/module_exists/HEAD
lazysoundsystem
+1  A: 

Drupal has a hook you can implement and add in whatever code you'd like to the footer of the page - hook_footer. See http://api.drupal.org/api/function/hook_footer/6

Roger Saner
this should work.
barraponto
+1  A: 

There have already beed made some good suggestions:

  • Using a block
  • Editing templates
  • Using preprocess function.

The easiest thing would be to add a block that you create, where you can put your custom markup. You could even create a special template for it, so you don't get your usual drupal block markup, but only what you write in the block content.

That should cover your needs:

  • You have 100% control over where the markup is generated (You can define the region in your them)
  • You have 100% control over what markup is generated

Now if you don't want to use blocks, because you don't want the site admins to know about the block, the 2nd best thing would be:

  1. Add a checkbox to your theme settings.
  2. In your preprocess page hook, set a boolean variable if the checkbox is checked or not.
  3. In your page template, you check for the variable, if it's TRUE you write your markup where you want it.

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

You can do pretty much the same in a custom module, but it wont make much sense to do this in a module, since it's purely presentation and you are dependent on your theme anyways.

googletorp