Forum Moderators: open

Message Too Old, No Replies

How to solve var inside JavaScript?

         

toplisek

12:55 pm on Jul 6, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have the following code:
var data1 = {rss_source1: '{$myvars.myvariablename}'};
function app()
{
this.myfeed = data1.rss_source1
// this.myfeed= "data1.rss_source1"
}

As we know PHP executes before the page is loaded and I have defined var to read Smarty variable. Issue is that PHP has already been parsed when JavaScript runs. Both options will not work. How to solve this issue?

Storing them as properties of an object.
var data1 = {rss_source1: '{$myvars.myvariablename}'};

Is this correct as source feed is not detected.

lucy24

4:09 pm on Jul 6, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Generic answer: Does it need to be a variable in javascript? That is, will its value ever change after the page has loaded? Sometimes you can sidestep the server-vs-script problem by letting php read in any values it needs to read in, and simply put them into the page HTML as if they were constants.

toplisek

4:51 pm on Jul 7, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is an issue as simply put constant (all the time the same) in the page HTML.
Javascript is app function and needs to be inside Javascript not HTML.