Forums Archive Index > SmartMenus 5 > Can I add menus at runtime (put s_add in code)?
Date: 22 Dec 2003 9:10 am
The manual says that the "s_add"s has to be defined in s_arrays.js...
Can this be done in the html page itself? I want to fill the menus with my CMS (content managing system) eZpublish, and this will have to be done in the template's html page (using PHP). How do I do this?
Date: 22 Dec 2003 11:26 am
:!: Update: v5.2+ :!:
Well to define your menus in the pages' source, you will need to do some customizations to the "s_loader.js" file and use a bit different technique from the documented.
I will try to describe what you should do step-by-step.
First open the "s_loader.js" file in a text editor and replace the following code at the end of the file:
Code:
if(s_iE||s_nS4||s_nS||s_oP){document.write(s_tm1);document.write(s_tm2);if(s_tm3!="")document.write(s_tm3)}if(s_kN)document.write(s_tm1+s_tm2+s_tm3);
with this code:
Code:
if(s_iE||s_nS4||s_nS||s_oP||s_kN)document.write(s_tm1);
It's not necessary to say that you will have to use the modified "s_loader.js" file instead of the original :)
Now how to setup your pages:
1) The link to the "s_loader.js" file should be set as normally (preferably right after the BODY tag).
2) After that in the source of your page should be located the menu definitions (not necessarily exactly after the link to "s_loader.js"- you can have other source between them- just the order is important).
3) And after the menu definitions you will have to add the following HTML code (again not necessarily exactly after the menu definitions):
Code:
<script language=JavaScript1.2>
if(s_iE||s_nS4||s_nS||s_oP){
document.write(s_tm2);
if(s_tm3!="")
document.write(s_tm3)
}
if(s_kN)
document.write(s_tm2+s_tm3);
</script>
Be sure that the above is direct child to the BODY tag (it's not nested in any other tag).
And now how an example page looks:
Code:
<html>
<head>
<title>example</title>
<script language=JavaScript>
function s_show(){return false}
function s_hide(){return false}
if(window.event+''=='undefined')event=0
</script>
</head>
<body>
<script language=JavaScript1.2 src=s_loader.js></script>
<!-- ANY PAGE CONTENT MAY BE PLACED HERE -->
<script language=JavaScript1.2>
s_add(
{
N:'example',LV:1,W:130,T:15,L:0,P:false,S:example},
[
{U:'http://www.smartmenus.org/',T:'SmartMenus.org'},
{U:'http://www.smartmenus.org/',T:'SmartMenus.org'},
{U:'http://www.smartmenus.org/',T:'SmartMenus.org'}
]
);
</script>
<!-- ANY PAGE CONTENT MAY BE PLACED HERE -->
<script language=JavaScript1.2>
if(s_iE||s_nS4||s_nS||s_oP){
document.write(s_tm2);
if(s_tm3!="")
document.write(s_tm3)
}
if(s_kN)
document.write(s_tm2+s_tm3);
</script>
</body>
</html>
Date: 26 Apr 2005 2:13 pm
I am proving the suggested code and it does not work to me, I have made exactly the described steps and i can't define my menus in the sources pages. You could help me with a code that works or that can download... Thanks!
smartmenus wrote:
:!: Update: v5.2+ :!:
Well to define your menus in the pages' source, you will need to do some customizations to the "s_loader.js" file and use a bit different technique from the documented.
I will try to describe what you should do step-by-step.
First open the "s_loader.js" file in a text editor and replace the following code at the end of the file:
Code:
if(s_iE||s_nS4||s_nS||s_oP){document.write(s_tm1);document.write(s_tm2);if(s_tm3!="")document.write(s_tm3)}if(s_kN)document.write(s_tm1+s_tm2+s_tm3);
with this code:
Code:
if(s_iE||s_nS4||s_nS||s_oP||s_kN)document.write(s_tm1);
It's not necessary to say that you will have to use the modified "s_loader.js" file instead of the original :)
Now how to setup your pages:
1) The link to the "s_loader.js" file should be set as normally (preferably right after the BODY tag).
2) After that in the source of your page should be located the menu definitions (not necessarily exactly after the link to "s_loader.js"- you can have other source between them- just the order is important).
3) And after the menu definitions you will have to add the following HTML code (again not necessarily exactly after the menu definitions):
Code:
<script language=JavaScript1.2>
if(s_iE||s_nS4||s_nS||s_oP){
document.write(s_tm2);
if(s_tm3!="")
document.write(s_tm3)
}
if(s_kN)
document.write(s_tm2+s_tm3);
</script>
Be sure that the above is direct child to the BODY tag (it's not nested in any other tag).
And now how an example page looks:
Code:
<html>
<head>
<title>example</title>
<script language=JavaScript>
function s_show(){return false}
function s_hide(){return false}
if(window.event+''=='undefined')event=0
</script>
</head>
<body>
<script language=JavaScript1.2 src=s_loader.js></script>
<!-- ANY PAGE CONTENT MAY BE PLACED HERE -->
<script language=JavaScript1.2>
s_add(
{
N:'example',LV:1,W:130,T:15,L:0,P:false,S:example},
[
{U:'http://www.smartmenus.org/',T:'SmartMenus.org'},
{U:'http://www.smartmenus.org/',T:'SmartMenus.org'},
{U:'http://www.smartmenus.org/',T:'SmartMenus.org'}
]
);
</script>
<!-- ANY PAGE CONTENT MAY BE PLACED HERE -->
<script language=JavaScript1.2>
if(s_iE||s_nS4||s_nS||s_oP){
document.write(s_tm2);
if(s_tm3!="")
document.write(s_tm3)
}
if(s_kN)
document.write(s_tm2+s_tm3);
</script>
</body>
</html>
Date: 28 Apr 2005 11:59 am
The guide above works with SmartMenus v5.5. You probably have done something wrong. Here's a working example:
--> http://www.smartmenus.org/down/Menu_Definitions_in_Page_Source.zip