Jump to content

Dynamic css into a module


Recommended Posts

Hi,
i'm developping a new module that include a slider with jquery.
The problem that i want to make some parameter of that module in a dynamic way, for example, tha height of the module, the background-color, the width etc,
To do that i have to make some changes in css and js with that parameter;
 
I know that when i want to put a css / js file into a module i do this :

Tools::addJS(($this->_path).'path/to/file.css');

but the problem that i want to put also passed parameters (width,height etc) into that css file

 

PS : i cannot use inline-style (style="width:xxx") due to many reasons.

 

Please help me to find the solution.

 

Thanx in advance.

Link to comment
Share on other sites

You can write css into the file at the time you save configuration in the back office, using a normal fwrite :)

 

Hi Nemo1, first sory for the duplicate post that i made, it's a mistake, sorry :)

 

Thanx for the speedy reply :) 

 

I wanted to do that with the "fwrite" function in php, but the problem that i'm afraid that makes a problem with servers and permissions for the persons that have that stricted permissions in their hots.

any other way please ?

Link to comment
Share on other sites

No other way I am afraid, not that I know. css files cannot contain variables

 

Yes but is there a function in Prestashop that load css ? something like this for example : 

SomeClass::loadCss($css_content)

and the function will be like that : 

class SomeClass {
...
...
...
...
...
public static function loadCss ($css_content) {
   // some code to load that $css_content into a <style> tag in <head> tag, like Tools::addCSS() do..
}

}
Link to comment
Share on other sites

Hi Nemo1, first sory for the duplicate post that i made, it's a mistake, sorry :)

 

Thanx for the speedy reply :)

 

I wanted to do that with the "fwrite" function in php, but the problem that i'm afraid that makes a problem with servers and permissions for the persons that have that stricted permissions in their hots.

any other way please ?

 

tip: if they installed your module, then there would not be a 'write' issue if you stay within your module folder. :)

 

nemo1's sage advice is best to follow, but don't be afraid to change within the module folder.

  • Like 1
Link to comment
Share on other sites

Ahh, I thought you didn't want o use that!

In that case you can simply use a smarty assign and then

 

<style>

.body {

    background: {$variable}

}

</style>

 

yes but if i assign a smarty variable, this will not put this <style> tag in the <head> section, dont forget that is an installable module, so wen a module want to put something in style it must be put in the <head> section for SEO things....

 

According to my search Prestashop havn't a similar functionnality, even in the new version 1.6.

Well for the moment i have to minimize some configurable settings in my module untill i find a way to do that...

Link to comment
Share on other sites

tip: if they installed your module, then there would not be a 'write' issue if you stay within your module folder. :)

 

nemo1's sage advice is best to follow, but don't be afraid to change within the module folder.

 

Ah yes that's right !! i forgot this point !!

So for the moemnt editing the "fwrite" function of php is the best solution.

 

Thanx in advice gus :)

  • Like 1
Link to comment
Share on other sites

regarding to the css styles

why not to use js and create these styles dynamically? :)

 

for example, in header.tpl create own variables:

 

<script>

var BgColor = '#000000';

</script>

 

then with js script like you can change styles:

 

<script>

$(document).ready(function(){
$("#myElement").css("background-color", BgColor);

});

</script>

 

of course you can create var BgColor dynamically, based on Configuration::get('myvariable'); or any other stuff you want :-)

  • Like 1
Link to comment
Share on other sites

×
×
  • Create New...