News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

[BUG] Unable to add javascript in index.template.php

Started by zeridon, October 03, 2008, 03:08:14 AM

Previous topic - Next topic

zeridon

While developing a mod i require inclusion of javascript files.

The decision was to include them in the head section just right after the meta tags.

The mod instals without a problembut the JS files do not appear in the rendered output to the browser. The js files inclusion is in place in the index.template.php

Now the required data:
* Version: 2.0 Beta4 Public
* Themes: default, overviewlight 2.04_b
* mods: related topics, google map, show local url titles
* languages: english, bulgarian-utf8
* encoding: utf8
* server: debian, apache22, php5, mysql5

how to reproduce: Create mod that modifies index.template.php by adding javascript files in the header section right after the meta tags. Use the same costruction for inclusion as used in the stock script files. Aply the mod, check the rendered output.

Nathaniel

Its difficult to reproduce this bug, without seeing the actual way that you have tried to include that javascript file. Can you post the code/edit that you used to include the javascript file?
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

zeridon

#2
<file name="$themedir/index.template.php">
<operation>
<search position="before"><![CDATA[<meta name="keywords" content="', $context['meta_keywords'], '" />]]></search>
<add><![CDATA[ <!-- // motranslator mod start -->
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/scripts/motrans.js?b4"></script>
<script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/scripts/CookieManager.js?b4"></script>
<!-- // motranslator end -->
]]></add>
</operation>
</file>

Nathaniel

Try this:
<file name="$themedir/index.template.php">
   <operation>
      <search position="before"><![CDATA[<meta name="keywords" content="', $context['meta_keywords'], '" />]]></search>
      <add><![CDATA[   <!-- // motranslator mod start -->
         <script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/scripts/motrans.js?b4"></script>
         <script language="JavaScript" type="text/javascript" src="', $settings['default_theme_url'], '/scripts/CookieManager.js?b4"></script>
         <!-- // motranslator end -->]]></add>
   </operation>
</file>


You need the ending ']]></add>' part. ;)
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

zeridon

it is there and still does not work ... the mod is applied without a glitch but after that there are no additional javascript lines in the head section

Nathaniel

Which theme are you checking to see that its installed for? It will only install for the default theme, unless you ask it to install for other themes.

Also, this might help. Instead of making the edit in the headers, you can use this code earlier on in a source file (probably somewhere were you mod setup its other stuff):
global $context, $settings;
$context['html_headers'] .= '         <script language="JavaScript" type="text/javascript" src="'. $settings['default_theme_url']. '/scripts/motrans.js?b4"></script>
         <script language="JavaScript" type="text/javascript" src="'. $settings['default_theme_url']. '/scripts/CookieManager.js?b4"></script>';


That might work better.

Its unlikely that this is actually a bug with SMF, its more likely that there is a syntax error with the xml code. You could try using 'replace' instead of 'before' (you can easily change it, by having the search code in both the search and add tags).
SMF Friend (Former Support Specialist) | SimplePortal Developer
My SMF Mods | SimplePortal

"Quis custodiet ipsos custodes?" - Who will Guard the Guards?

Please don't send me ANY support related PMs. I will just delete them.

metallica48423

why not place it with the rest of the javascript includes?

also, afterwards, have you cleared the file cache?
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

QuoteMicrosoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"


Useful Links:
Online Manual!
How to Help us Help you
Search
Settings Repair Tool

zeridon

i managed to resolve the issue ... some freakin' ... stuff was going on

Advertisement: