CMS Development

spotthehub
Participante

Choice field value issues

resolver

Hi, I'm creating a module and would like to add a custom font option to it.  

I've created simple css hubl code like this: 

 

p, li, h1, h2, h3, h4, button, span, a {
font-family: {{ module.font_family }};
}

 

and created a font_family choice field like this: 

 

spotthehub_0-1626813624338.png

 

but it's not rendering the output correctly:

p,li,h1,h2,h3,h4,button,span,a{font-family:}

 I've tried font-family: {{ module.font_family.value }}, etc...

 

Anyone see what I'm doing wrong?

 

Thanks

Ben

0 Me gusta
1 Soluciones aceptada
miljkovicmisa
Solución
Colaborador líder | Partner nivel Platinum
Colaborador líder | Partner nivel Platinum

Choice field value issues

resolver

Hello @spotthehub and thanks for sharing your issue.


First of all, css in modules is very limited in comparison to html, thus you won't be able to access your value from the font_family from the css of the module. Here is more info on that.

 

For that matter you should probably use the require_css block in the html of the module like this:

 

{% require_css %}
<style>
  p,li,h1,h2,h3,h4,button,span,a{
    font-family: {{ module.font_family.value }} ;
  }
</style>
{% end_require_css %}

 

 

This and much more regaring modules is all very well documented in this article about module development.

 

I hope I gave you some direction what to look at, if it helped mark this answer as a solution.

Ver la solución en mensaje original publicado

3 Respuestas 3
webdew
Guía | Partner nivel Diamond
Guía | Partner nivel Diamond

Choice field value issues

resolver

Hi @spotthehub ,

Use rich text under module and get option font-family. Check screenshot:
https://prnt.sc/1ebwsh6

Hope this helps!


If we were able to answer your query, kindly help the community by marking it as a solution.

Thanks and Regards.

0 Me gusta
spotthehub
Participante

Choice field value issues

resolver

Hey @miljkovicmisa thanks for the help.  This worked well for my needs.

I was confused by this section in the documentation that shows variables being accessed: 

spotthehub_0-1626874405492.png

 

miljkovicmisa
Solución
Colaborador líder | Partner nivel Platinum
Colaborador líder | Partner nivel Platinum

Choice field value issues

resolver

Hello @spotthehub and thanks for sharing your issue.


First of all, css in modules is very limited in comparison to html, thus you won't be able to access your value from the font_family from the css of the module. Here is more info on that.

 

For that matter you should probably use the require_css block in the html of the module like this:

 

{% require_css %}
<style>
  p,li,h1,h2,h3,h4,button,span,a{
    font-family: {{ module.font_family.value }} ;
  }
</style>
{% end_require_css %}

 

 

This and much more regaring modules is all very well documented in this article about module development.

 

I hope I gave you some direction what to look at, if it helped mark this answer as a solution.