Choice field value issues

SOLVE
spotthehub
Participant

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 Upvotes
1 Accepted solution

Accepted Solutions
miljkovicmisa
Solution
Contributor | Gold Partner

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.

View solution in original post

3 Replies 3
miljkovicmisa
Solution
Contributor | Gold Partner

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.

View solution in original post

spotthehub
Participant

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

 

webdew
Top Contributor | Diamond Partner

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 Upvotes