CMS Development

spotthehub
Participant

Choice field value issues

Résolue

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 Votes
1 Solution acceptée
miljkovicmisa
Solution
Contributeur de premier rang | Partenaire solutions Platinum
Contributeur de premier rang | Partenaire solutions Platinum

Choice field value issues

Résolue

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.

Voir la solution dans l'envoi d'origine

3 Réponses
webdew
Guide | Partenaire solutions Diamond
Guide | Partenaire solutions Diamond

Choice field value issues

Résolue

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 Votes
spotthehub
Participant

Choice field value issues

Résolue

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
Solution
Contributeur de premier rang | Partenaire solutions Platinum
Contributeur de premier rang | Partenaire solutions Platinum

Choice field value issues

Résolue

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.