generating HTML with javascript that contains php and ifs -
i have large amount of html , css contains php (session based content) php must. need session information (no cookies wont do).
the html , css standard divs looking @ previous question: is there best practice generating html javascript
which gives me answer need, if using html , css, if need use js if statements chose part of template needs different , if need use php same?
i moving code away heavy server side scripting , moving as can front end processing, issue need have php , if statements (js if statements) within $.template
can use php variables in js templating system , how use js if statements within templating function?
var moo = 1 var t = $.template('<div>this code, moo?. if(moo == 1){moo 1..}else{moo not 1}</div>')
as commented, can declare , check variables before using it.
example:
var moo = 2 + 2 == 4 ? "yes moo" : "no moo"; var t = $.template('<div>this code, moo?. moo '+ moo +'</div>');
but if working large data, should consider use string variable , concatenate new strings needed:
var str = "<div>"; if( moo == 4 ) str += "moo equals 4"; else str += "moo not equals 4"; str += "</div>"; // , when have string completed... var t = $.template(str);
by way can concatenate need without headaches.
Comments
Post a Comment