We use the joomla.assets.json to load google fonts in one of our template (J4). We would like to use the same template for multiple sites and offer the option to load a different font. To do this I was thinking of adding a template parameter that contains the google font URL and use this inside the joomla.assets.json file. But I don't think this can be done since the asset file is not PHP.
{
"name": "template.googlefont",
"type": "style",
"uri": "[GOOGLE_FONTS_URL_PARAMETER_VALUE__HERE]"
}
This is not possible, correct?
We could load the google font in the template in a different way of course. But it would be better to use the assets file, because that is what this file is for right?
Maybe there are other benefits of being able to use variable sin the assets file? Or not ;-)
Labels |
Added:
No Code Attached Yet
|
That sound great. But I'm not sure where to start ;-)
I did think of an alternate solution:
Create multiple assest in the json file for different Googble font URL's with unique names (fontset1, fontset2). Then add a parameter to the template where one of the 'font sets' can be chosen. Then load the asset based on the parameter name using PHP.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-01-28 09:08:47 |
Closed_By | ⇒ | Fedik |
You can achieve it with a custom class for your asset item. That what Dimitris suggested.
You can find more info here https://docs.joomla.org/J4.x:Web_Assets#Advanced:_Custom_WebAssetItem_class
Create multiple assest in the json file for different Googble font URL's with unique names (fontset1, fontset2).
That also a good solution
You can implement your own, this could be a good starting point: