views:

191

answers:

2

I am quite new to using Joomla. I have created a custom module, however I would like to add some code near the </body> tag (or near the opening <body> tag) so it is guaranteed to be not nested in any tables whatsoever that might be in the template.

I have located details on how to do this within a content plug-in, however I would like to just have the module.

Any ideas? Thank you.

+1  A: 

If the entire module is to go just before </body> then you will need to create a module position in your template. In the file /templates/[name]/index.php put this in the required location:

<jdoc:include type="modules" name="endofpage" />

Now when you add the module you can put it in the position "endofpage" (or a better name if you choose).

Otherwise, if your main module content is to be within the regular design, you will have to create two modules or use the plugin method like you said. There is no way to inject content into two different parts of a page with one module (unless you use Javascript to generate it).

DisgruntledGoat
Thank you, however the module will be placed anywhere within the template. There is simply some other code that I need to have placed near the <body> or </body> that I know is not nested in tables. I might need to use JavaScript then.Within a module you can add JavaScript tags, seems wierd I can't place some code directly after the opening <body> tag that I can guarantee is not within a <table> tag etc.
Luke
I used jQuery to append the code into the <body> tag. Thanks for your guidance
Luke
+1  A: 

I'm not quite sure I follow why what DisgruntledGoat suggested won't work.

If you want to add code immediately at the start of the

1) Create a new module position in your template.xml (call it startofpage, or endofpage) 2) In you template index.php place the code 3) Depending on what you want to output, change the style attribute of the module

</head>
<body>
<jdoc:include type="modules" name="startofpage" style="xhtml" />
...YOUR CONTENT IN HERE
<jdoc:include type="modules" name="endofpage" style="xhtml" />
</body>
</html>
Jeepstone
Sorry I should be more clear in the question. It needs to be entirely self contained withn the module. I don't want to be asking people that install the module to add <jdoc: include etc.I would have thought the module would have access to modify just after the opening <body> tag. You can add script tags without problems in the <head>
Luke
Ah I see. If your template doesn't have a module in that specific position, then you'd need to append it using javascript, such as jQuery. Look for the .append() method, much as DisgruntledGoat said :o)
Jeepstone