CMS Development

SandyG1
Mitwirkender/Mitwirkende | Partner
Mitwirkender/Mitwirkende | Partner

Accessing theme fields from a module

Is it possible to access settings of the theme within a module?

 

I seem to be having issues when using settings at a module level which are in the theme..

 

This works outside of a module but not inside of a module

 

{{ theme.global_colors.additional_1_color.color }}
0 Upvotes
6 Antworten
vish891
Mitglied

Accessing theme fields from a module

Hey

 

Any use case of why you would want to use this in a module 🙂

 

If you want dynamically set the color may be target it using a class?

0 Upvotes
SandyG1
Mitwirkender/Mitwirkende | Partner
Mitwirkender/Mitwirkende | Partner

Accessing theme fields from a module

Well, if I want for instance a title module to use a preset colour from the Theme defaults.

 

If I can't access the color from the theme settings then creating a class isn't going to be much help either is it?

 

Can you elaborate on how you think creating a class might help?

 

Please consider the fact that I may want to use this color on a background-color, color, or border color.

0 Upvotes
vish891
Mitglied

Accessing theme fields from a module

So all default headers(h1,h2,h3 etc. ) and titles tags can be set.If you are using any of those it should work automatically if not the class would come in handy

 

you can set the colors you want in a specific class.

 

For ex:

 

.custom-class{

color: {{ color_var }};
background-color:{{ bg_color }}

border-color:{{ theme.buttons.border_color }}

}

0 Upvotes
SandyG1
Mitwirkender/Mitwirkende | Partner
Mitwirkender/Mitwirkende | Partner

Accessing theme fields from a module

I see what you're saying.

Essentially, I'd need to create seperate classes though for each of the properties.

 

.theme-primary-bg-color{
 background-color: {{ theme.colors.primary }}
}

.theme-primary-color{
 color: {{ theme.colors.primary }}
}

.theme-primary-border-color{
 border-color: {{ theme.colors.primary }}
}

.theme-secondary-bg-color{
 background-color: {{ theme.colors.secondary}}
}

.theme-secondary-color{
 color: {{ theme.colors.secondary}}
}

.theme-secondary-border-color{
 border-color: {{ theme.colors.secondary}}
}

Although slightly longwinded, it could work

0 Upvotes
vish891
Mitglied

Accessing theme fields from a module

I just tried accessing the colors in module i was able to.

 

Syntax:

 

Screen Shot 2020-07-20 at 9.41.14 AM.png

 

 

SandyG1
Mitwirkender/Mitwirkende | Partner
Mitwirkender/Mitwirkende | Partner

Accessing theme fields from a module

That's right!

Thanks for your help.


I found out over the weekend that CSS files can't utilise variables within a module.

 

Which makes complete sense considering you wouldn't be able to have 2 of the same module with different colour referenced in a CSS file. Just doesn't make sense and I don't actuall know what I was thinking tbh Lachender Smiley

0 Upvotes