Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odpovědi
5219 Zobrazení

Hi all,

I'm using odoo 10

I have 2 websites in odoo with JS. For exemple, Website1 and Website2.

When I’m using Website1, the Website2’s JS file is loaded and used.
I’d like to separate JS files, one for each website, not for both. I have the same issue on CSS files.

I add this file in 'website.assets_frontend'

Do you have a solution ?

Thx

Avatar
Zrušit

why don't you implement different modules for each site to customize things individually ?

Nejlepší odpověď

Hi Boehm Benjamin,

This solution would surely help you.

1. Create new config parameter check the parameter inside your xml code where you load your js and css files.

2. Define your custom function in config parameter model which help you to get your parameter value.

E.g.

PARAMS = [
('your_module_name.parameter1', _('parameter_value')),
('your_module_name.parameter2', _('parameter_value')),

]
class IrConfigParameter(models.Model):
_inherit = 'ir.config_parameter'

@api.model
def get_your_parameter(self):
res = {}
for parameter, default_val in PARAMS:
value = self.env['ir.config_parameter'].get_param(parameter, default_val)
res[param] = value.strip()
return res

3. Use the function in your xml code where you will load your js,css,less file conditionally.

E.g.

<template id="assets_sample_frontend" name="give_name_which_you_want" inherit_id="web.assets_frontend">
<xpath expr="." position="inside">

<t t-set="variable_here"
t-value="request and request.env['ir.config_parameter'].get_your_parameter().get('pass_key_here')"/>
<!-- use your variable here in condition-->
<t t-if="variable_here == '1'">
<link rel="stylesheet" type="text/less" href="/your_module_name/static/src/less/sample.less"/>
<link rel="stylesheet" type="text/less" href="/your_module_name/static/src/js/your_file.js"/>
</t>
</xpath>
</template>

Hope this might help you.

Happy Odooing.

Rgds,

Anil.


Avatar
Zrušit
Autor Nejlepší odpověď

Thx Anil, I will try. But in IrConfigParameter class, what is the 'PARAMS' element ?

I'm newbie in odoo and python

Avatar
Zrušit

I understood, let me modify my example. it is list of tuples in which you could defines number of parameter to match.

I've updated my answer. you need to define in same py file outside the class to access it globally in same py file.

Autor

Many Thx for your help, but I don't understand how it works. I have copied your code in my module for Website1.

On my Website2, I don't have CSS and JS files, this is the CSS file of my theme.

Autor

I added a test on my JS and it works. For my CSS, i continue to search

Nejlepší odpověď

Multi website is not supported, but it is possible if you really know what you have to do. Also a lot of work has been done by OCA contributors, you may want to check this little gem:

https://github.com/OCA/website/tree/10.0/website_multi_theme

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
pro 17
3874
1
čvn 24
1079
2
kvě 21
6876
1
led 20
7657
1
čvc 19
3500