No Code Attached Yet
avatar jjnxpct
jjnxpct
27 Jan 2023

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 ;-)

avatar jjnxpct jjnxpct - open - 27 Jan 2023
avatar joomla-cms-bot joomla-cms-bot - change - 27 Jan 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 27 Jan 2023
avatar dgrammatiko
dgrammatiko - comment - 27 Jan 2023

You can implement your own, this could be a good starting point:

avatar jjnxpct
jjnxpct - comment - 27 Jan 2023

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.

avatar Fedik Fedik - change - 28 Jan 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-01-28 09:08:47
Closed_By Fedik
avatar Fedik Fedik - close - 28 Jan 2023
avatar Fedik
Fedik - comment - 28 Jan 2023

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

Add a Comment

Login with GitHub to post a comment