1

I want to use the google fonts in my module, so that you can pick a font rather than having to type it out. I picked google fonts because it seems like the most "future proof" way, so I wanted to learn that.

I want someone in the back end to be able to select one of these from a drop-down menu.

How do I do this the best way?
What is the best way to put it into my xml file without typing every option myself?

1

Firstly create a select dropdown field in your XML file like so:

<field name="font" type="list" default="Istok+Web" label="Font">
    <option value="Istok+Web">Istok Web</option>
    <option value="Lato">Lato</option>
</field>

Then in your mod_mymodule.php file, add the following:

$font = $params->get('font');
JHtml::_('stylesheet', 'http://fonts.googleapis.com/css?family=' . $font);
  • I got that, haha, thanks. But how can I get the Entire list of Google fonts without having to type them myself manually? – Hocho Nov 25 '14 at 13:51
  • 1
    Ahh, you will need to create a custom form field and use Google's API to get a list of all fonts. This is a completely different question though ;) – Lodder Nov 25 '14 at 13:57
0

No point in re-inventing the wheel, just look at how some of the big frameworks, like T3, do this;

https://github.com/t3framework/t3/blob/master/source/plg_system_t3/includes/gfont/T3GFont.php

However, I really cant see why you would want to do this from within a module. Site styles, including font choices, should be determined by the template. Doing it from within your module can only cause conflict with the wishes of the site owner (who picked the template, and the font styles that come with it.), so it is something that you should best avoid.

This is not something that modules should do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.