Elxis CMS Forum

Extensions => Templates => Topic started by: datahell on April 12, 2009, 14:05:50

Title: OnLoad in body tag - Elxis 2009.0
Post by: datahell on April 12, 2009, 14:05:50
Elxis 2009.0, or newer, has a build-in function that allows developers to load JavaScript in body tag using the attribute onload. To be able to perform this task the template should be compatible with this feature.

Read how to make your template compatible with this feature or how to use this feature if you are a PHP developer. (http://wiki.elxis.org/wiki/OnLoad_in_body_tag)
Title: Re: OnLoad in body tag - Elxis 2009.0
Post by: pavel on April 13, 2009, 13:55:00
Is there any possibility for future elxis releases to insert body id=".." tag dynamically?

Currently I found a way to solve it by having 2 identical templates with CSS / JS files pointing to the subfolder of my main template and the only difference is the index.php template file, where body id is different. Then I assign a different templates as required, but both templates are controlled by the same CSS/JS files and the same images.

It works, but...  I have two (or more) template index.php files.  So in case of some major changes in future it will be a lot more difficult to update all.  Possibility to insert body ID tag dynamically can solve this problem. 

I am not sure how this can be implemented.  Perhaps via component admin...
If not for 2009, then for future. 
Title: Re: OnLoad in body tag - Elxis 2009.0
Post by: datahell on April 13, 2009, 14:51:41
Why you need an ID attribute in the body tag? The body tag is unique. If you need to style it using CSS it is easy to do it like this:

body {
margin: 0;
}
Title: Re: OnLoad in body tag - Elxis 2009.0
Post by: pavel on April 13, 2009, 16:26:02
I want some pages behave / look differently, but at the same time the site must look the same.  If I want to add certain behavior to h2 tag (or hide the paragraph following h2 only on the pages that show content, but not for the front page or contacts page, then I need to create a new template just for this modification.
It would be easier to use the same template and specify property for #bodyid h2 or any other tag I want to customize for the page.

There can be a situation where menu has to behave slightly differently on different pages.  For example, stay expanded on one and be closed (with a drop down list) on the other page.  To achieve this one would need to create a different template or... change a body tag and add a few lines to the same CSS file.

Anyway, it is a rare case, so if it is a headache to implement it is not so important.
Title: Re: OnLoad in body tag - Elxis 2009.0
Post by: datahell on April 13, 2009, 19:25:36
I don't see the necessity of this addition in your case. You can have individual page/modules styling using css suffixes, with the power of php, using javascript, with many methods and tricks.

The onload feature added for the PHP developers, not for the template designers. As a template designer you have available the template files and you can do what ever you like, you can set ids, css classes, edit javascript and css, etc. But the php developer does not even knows which is the template a web site is running. He can not access the template files, and he can not modify the body tag.That's why the onload is helpful for them.
Title: Re: OnLoad in body tag - Elxis 2009.0
Post by: ks-net on April 13, 2009, 19:44:28
datahell is right ....

Quote
If I want to add certain behavior to h2 tag (or hide the paragraph following h2 only on the pages that show content, but not for the front page or contacts page, then I need to create a new template just for this modification.

for  example...  using jquery you can format(hide or even rewrite) different elements on different pages ...
thats exactly the reason of existence of those javascript frameworks

eg.  ... wile you write your content on specific  page you can add also... to hide h2 (jquery)
Code: [Select]
<script> 
 $(document).ready(function() {
 $('h2').hide();
});
</script>

or you can add a new class to h2 for that page, of course you can write once a script  for many pages to format many elements ,,,
unlimited options
Title: Re: OnLoad in body tag - Elxis 2009.0
Post by: pavel on April 17, 2009, 15:18:36
All clear.  Thanks.