How to use template parsing in javascript

edited August 2015 in Modules
Hi,
I am using the template parser function in some of my pages.
Now I have a js snippet
// Marker var locations = [ ['Kliniken des Main-Taunus-Kreises<br/>Bad Soden am Taunus', 50.151331, 8.514133, '{assets_path("icons", "mapIcon_hospital.png")}'], ['Feuerwache<br/>Bad Soden', 50.139131, 8.511029, '{assets_path("icons", "mapIcon_fire.png")}'], ['Feuerwache<br/>Stadtteil Neuenhain', 50.158639, 8.495477, '{assets_path("icons", "mapIcon_fire.png")}'], ['Feuerwache<br/>Stadtteil Altenhain', 50.156875, 8.468608, '{assets_path("icons", "mapIcon_fire.png")}'], ['Taunusresidenzen', 50.143738, 8.511266, '{assets_path("icons", "mapIcon_senioren.png")}'], ['Augustinum Seniorenresidenz', 50.153375, 8.503919, '{assets_path("icons", "mapIcon_senioren.png")}'], ['Seniorenresidenz<br/>Bad Soden am Taunus', 50.134313, 8.506416, '{assets_path("icons", "mapIcon_senioren.png")}'], ['City Arkaden<br/>Bad Soden am Taunus', 50.143863, 8.501900, '{assets_path("icons", "mapIcon_mtz.png")}'], ['Main-Taunus-Zentrum', 50.116511, 8.530810, '{assets_path("icons", "mapIcon_mtz2.png")}'], ];

The assets_path function is not parsed, but translated into
// Marker var locations = [ ['Kliniken des Main-Taunus-Kreises<br/>Bad Soden am Taunus', 50.151331, 8.514133, '{ assets_path("icons", "mapIcon_hospital.png")}'], ['Feuerwache<br/>Bad Soden', 50.139131, 8.511029, { assets_path("icons", "mapIcon_fire.png")}], ['Feuerwache<br/>Stadtteil Neuenhain', 50.158639, 8.495477, '{ assets_path("icons", "mapIcon_fire.png")}'], ['Feuerwache<br/>Stadtteil Altenhain', 50.156875, 8.468608, '{ assets_path("icons", "mapIcon_fire.png")}'], ['Taunusresidenzen', 50.143738, 8.511266, '{ assets_path("icons", "mapIcon_senioren.png")}'], ['Augustinum Seniorenresidenz', 50.153375, 8.503919, '{ assets_path("icons", "mapIcon_senioren.png")}'], ['Seniorenresidenz<br/>Bad Soden am Taunus', 50.134313, 8.506416, '{ assets_path("icons", "mapIcon_senioren.png")}'], ['City Arkaden<br/>Bad Soden am Taunus', 50.143863, 8.501900, '{ assets_path("icons", "mapIcon_mtz.png")}'], ['Main-Taunus-Zentrum', 50.116511, 8.530810, '{ assets_path("icons", "mapIcon_mtz2.png")}'], ];

I think there is some problem with { and js...
How can I solve this?

Comments

  • edited 3:01PM
    Is the above content being inputted through the CMS or is it set in a static view/layout file? If the latter, just use normal PHP code <?=assets_path("icons"....)?>
  • edited 3:01PM
    It is entered in the cms
  • edited 3:01PM
    To prevent confusion between the javascript and the templating delimiters, it automatically inserts the space when it is inside a script block.

    Perhaps another way would be to create an "iconsPath" variable in your layout (not in the page) and then just reference that javascript variable:


    // In your layout (probably in the head) <script>var iconPath = assets_path("icons");</script>
    // Marker var locations = [ ['Kliniken des Main-Taunus-Kreises<br/>Bad Soden am Taunus', 50.151331, 8.514133, iconPath + "mapIcon_hospital.png"], ..... ];
  • edited 3:01PM
    ah that worked. Thanks!
Sign In or Register to comment.