Using tags in javascript

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
harry1963
Posts: 10
Joined: Sun 4. Mar 2007, 19:17

Using tags in javascript

Post by harry1963 »

Maybe somebody can help me out
I'm making a website wich will inform people about almost anything in any city in the Netherlands. To make everything a lot easier is I use custom made tags.
For instance the tag {PLAATS}. This tag displays the cityname, the city's wapon and so on... In the header I want to place a part of google's map displaying the city.
For this I ported Wadehammers script (google maps as website background). This script uses a little javascript file whit the coordinates of the location to be displayed.
The problem iv'e got whit this is the following:
In the original script this file is called "map.js"
Because of the way is use this script it should be called {PLAATS}.js

Sadly the tag is not accepted as an varaible wich could be called Beverwijk. So is everything would be perfect {PLAATS}.js would show up as Beverwijk.js.

Does anyone know how this problem can be solved? Here's a sample of my output:
<script language="Javascript" type="text/javascript" src="{PLAATS}.js"></script>

should be:
<script language="Javascript" type="text/javascript" src="Beverwijk.js"></script>


Thanks Guys and Girls!

By the way... If there's something that rocks... than its PHPWCMS! :D :D
harry1963
Posts: 10
Joined: Sun 4. Mar 2007, 19:17

Re: Using tags in javascript

Post by harry1963 »

For those who want to see this working to get a better idea what my problem is I've posted two links below.
http://mijn-plaats.nl/index.php?heemskerk-in-het-nieuws
http://mijn-plaats.nl/index.php?beverwijk-in-het-nieuws
User avatar
Oliver Georgi
Site Admin
Posts: 9888
Joined: Fri 3. Oct 2003, 22:22
Contact:

Re: Using tags in javascript

Post by Oliver Georgi »

It would be better to use the JavaScript in better way. Define all points in 1 single JS file and then select it based on the tag name.

But hard to understand what you do here and why it fails. Several possible ways:

Code: Select all

var map_points = {
    Beverwijk: {lat: 0, long: 0},
    Other: {lat: 1, long: 1}
}
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
harry1963
Posts: 10
Joined: Sun 4. Mar 2007, 19:17

Re: Using tags in javascript

Post by harry1963 »

Hi Oliver,

Many thanks for your reply and some of it start to sink to my modest brain. It looks that what you advise me has graet potential. Thoug me being a nitwit towards javascript an forwarding those values (as you describe).... Can you give me a litle more explenation?


Kind regards,


Harry Roelofsen.
User avatar
Oliver Georgi
Site Admin
Posts: 9888
Joined: Fri 3. Oct 2003, 22:22
Contact:

Re: Using tags in javascript

Post by Oliver Georgi »

you define single global object/array with all values.

Then you just use the tag to define the active set in your template:

Code: Select all

<!-- JS: 
var map_points = {
    Beverwijk: {lat: 0, long: 0},
    Other: {lat: 1, long: 1}
}, activeCity = '{PLAATS}'; 
// just a test
alert(map_points[activeCity].lat);
-->
This is the direction I would go. Some test might be helpful if the map_points[activeCity] is an active value.
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
harry1963
Posts: 10
Joined: Sun 4. Mar 2007, 19:17

Re: Using tags in javascript

Post by harry1963 »

Hi Oliver thanks for your replies!

I found an answer for this/my issue and... one never knows... maybe somebody can use it.

The answer is pretty simple.
For displaying Google Maps as a background of my website is make use of Jquery's gmap3 script.
The problem I had was that it seemed impossible to put the latitude and longitude in a cmstag and use this tag in the head section of the page.

The answer to this problem is simply to put the javascript-code wich explains the Gmap-script what to do just above the </body> tag.

This way its possible to fill the latitude and longitude values in a tag and display the belonging map.

For an example you can look at : http://mijn-plaats.nl/index.php?amsterdam-nh

PHPWCMS... There's nothing better! (if it was a woman I would merry her immediately). :D :D
Post Reply