CMS Development

RSDigital
Member

How to set color and alpha of a module inside a template?

SOLVE

I have a custom module that allows a user to select a background color and opacity. I'd like to have this module available within different section templates, which isn't a problem, but I can't figure out the syntax to set the background color and the opacity from with a %dnd_module%  tag. I'm sure I'm missing something simple.

 

RSDigital_0-1652807759374.png

 

0 Upvotes
1 Accepted solution
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to set color and alpha of a module inside a template?

SOLVE

Hi @RSDigital

to get it right - you'd like to modify a section by a module? If so - it's gonna be hard. 

An easier approach would be to create a custom module instead of a section function. Here's an example.

 

Used functions:

- color function named "background color"

 

{% require_css %}
<style>
.{{name|md5}}{
background-color: rgba({{module.background_color.color|convert_rgb}}, {{module.background_color.opacity//100}});
{# more styling here #}
}
</style>
{% end_require_css %}

...
<div class="{{name|md5}}">
{# layout for your whole section #}
</div>

 

 

hope this helps

 

best, 

Anton

Anton Bujanowski Signature

View solution in original post

2 Replies 2
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

How to set color and alpha of a module inside a template?

SOLVE

Hi @RSDigital

to get it right - you'd like to modify a section by a module? If so - it's gonna be hard. 

An easier approach would be to create a custom module instead of a section function. Here's an example.

 

Used functions:

- color function named "background color"

 

{% require_css %}
<style>
.{{name|md5}}{
background-color: rgba({{module.background_color.color|convert_rgb}}, {{module.background_color.opacity//100}});
{# more styling here #}
}
</style>
{% end_require_css %}

...
<div class="{{name|md5}}">
{# layout for your whole section #}
</div>

 

 

hope this helps

 

best, 

Anton

Anton Bujanowski Signature
RSDigital
Member

How to set color and alpha of a module inside a template?

SOLVE

Thanks for your assistance!