problem to add file path to javascript variable

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Forum Members
Forum Members
Posts: 61
Joined: Wed Aug 08, 2018 4:59 pm

problem to add file path to javascript variable

Post by Sendlingur »

I've been spending most of my day trying to figure out how to pass a filepath to a javascript variable in an external .js file. I have done this before in a plain .php / .js files, but never in CMSMS.

What I need is to get the path from this file

Code: Select all

and assign the path to a javascript variable which is in this location

Code: Select all

I've tried every php variable to js variable method I've found on stackoverflow, google, etc to do this but with no luck.

I've wrapped plain php and javascript in {literal} but nothing is working out.

I have also tried to use the smarty {capture} and {assign} but still it is not working.

Now I'm totally out of options...can anyone more experienced in cmsms help me out?

for more clarification: the file is an .mp3 and I need to assign it's path to the .js variable for reading the ID3 tags bound to the file.
User avatar
Dev Team Member
Dev Team Member
Posts: 3313
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: problem to add file path to javascript variable

Post by velden »

You can not assign a smarty variable to be used outside the CMSMS scope/context.

You could however assign the value to a smarty variable and use that variable in your page template. So you can assign it to a global javascript variable which later can be used inside your /uploads/js/id3.js file

Code: Select all

var myPath = '{$entry->file_location}/{$entry->fields.Audio1->displayvalue}';
<__script__ src="{uploads_url}/js/id3.js"></__script>
Inside the id3.js file you should use the 'myPath' variable.
Post Reply

Return to “CMSMS Core”