javascript - Using PHP variables in jQuery plugin initialization? -


i have jquery image gallery plugin i'm using extensively throughout site i'm building php templates. in properties plugin initialization, of values remain same throughout site, aside few exceptions. in these instances, i'm wondering if it's ok me pass in value property via php; e.g. if there property called "thumbnailsvisible" in cases want set true, , in others, false. thus, there wrong assigning value corresponding variable , including following in jquery initialization within template:

thumbnailsvisible : <?php echo $thumbnailsvisible; ?> 

i realize externalize initialization in js file , create different versions needed, simpler provided there isn't wrong approach...

also, if there's different approach optimal, i'd appreciate sort of assistance. thanks.

yes. can this.

php processed on server side , sent client when it's processed.

you write php script return javascript , pass in argument.

eg.

<?php $thumbnailvisible = isset($_get['showthumb']) ? $_get['showthumb'] : 'false'; ?> $.func({     thumbnailsvisible: <?php echo $thumbnailvisible; ?> }); 

if doesn't work correctly, try specify content-type using header().

header('content-type: application/javascript'); 

place @ top of php script.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -