javascript - Joomla - how to Unset JS file from head using info given by user in template parameters -


i've unset both js , css files manually joomla template html head using usual method below.

unset($this->_scripts['/media/jui/js/bootstrap.min.js']); unset($this->_stylesheets['/media/jui/js/bootstrap.min.css']); 

my question this. possible store file , path info variable , use variable in place of path/file in above examples? , if so, might way this?

the reason? want give users of template ability enter multiple files/paths separated comma template parameters, store these various files/paths array, loop through array (unsetting/removing each 1 html head of template).

the purpose? 1 needs remove js html head , bottom of page reduce page load times, page transition flickers/white blinking, etc. in case don't want use plugin. i'd rather give users fine grained control if possible built template. of course, i'll have place in template parameters user add whatever js remove header bottom.

the code i'm using?

// grab js file paths user enters template parameters , add them array can loop through  $unsetjsfiles = $this->params->get( 'customfilesunsetjs' ); $unsetjsfilesarray = explode(',', $unsetjsfiles);  // loop through each js file path user entered , unset each 1 joomla html head    foreach ($unsetjsfilesarray $valuejs) {     $doc = jfactory::getdocument();     unset($doc->_scripts[$valuejs]);     } 

it doesn't seem working. have tested values outputted i'm looking via print_r, echo, etc. looping through doesn't work. first real question i've asked on stackoverflow. researched lot of threads , googled, 1 couldn't find answer to. many advice!

try declare $doc outside loop (above loop)!

and should unset , declare root!

unset($this->_scripts[juri::root(true) . '/media/jui/js/jquery.min.js']); 

so try (not tested!!):

// grab js file paths user enters template parameters , add them array can loop through  $doc = jfactory::getdocument(); $unsetjsfiles = $this->params->get( 'customfilesunsetjs' ); $unsetjsfilesarray = explode(',', $unsetjsfiles);  // loop through each js file path user entered , unset each 1 joomla html head    foreach ($unsetjsfilesarray $valuejs) {             unset($this->_scripts[juri::root(true) . $valuejs]); } 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -