-
-
Notifications
You must be signed in to change notification settings - Fork 16
Conversation
Added parameter(s) for GoogleFonts. Example fonts installed.
renamed scss files, changed if to switch
@Fedik Hello, maybe you are surprised being pinged from this repository. We are preparing some extensions of the Cassiopeia template, and one of them is providing local Google fonts and preload them. Now my question: The web asset manager which you have added to the core, can it also load fonts? Or do we sill have to use |
You still have to use WebAsset just provide an URI to the resource, if you example have an asset for fonts you can: $wa = $this->getWebAssetManager();
$wa->useStyle('template.cassiopeia.googlefont');
$this->getPreloadManager()
->preload($wa->getAsset('style','template.cassiopeia.googlefont')->getUri(), ['as' => 'style']); Btw, I forgot to make this change in the joomla core 😃 And note about the changes, you better make a local |
This should work: switch( $this->params->get('googleFontName'))
{
case "josefin-sans":
$wa->useStyle('font.josefin');
$this->getPreloadManager()->preload($wa->getAsset('style','font.josefin')->getUri(), ['as' => 'style']);
break;
case "montserrat":
$wa->useStyle('font.montserrat');
$this->getPreloadManager()->preload($wa->getAsset('style','font.montserrat')->getUri(), ['as' => 'style']);
break;
} |
@Fedik thank you for your help. I made the changes as you suggested. The css file is being loaded so Is it correct or should we expect a rel=preload? |
@Fedik I am trying to add the woff and woff2 files to cassiopeia/joomla.asset.json
I would like to be able to add
|
@Fedik sorry.. had to read all of your comments first
|
@Fedik Thanks a lot, you've helped much. |
Conflicts: templates/cassiopeia/index.php
Conflicts: templates/cassiopeia/index.php
…ure-cassiopeia/4.0-dev-google-fonts-enhancements
Replace switch
4.0 dev google fonts enhancements
Recent changes due to merged PR's may have broken it. At least I don't see it working here. Will continue to investigate. |
Problem is that |
The problem is that the compiled css is missing. It seems npm doesn't compile the |
@drmenzelit @hans2103 Ha that was it! The fonts scss files have to be added to the build script
The question is if that it really open for adding fonts later in overrides. Wouldn't it be better we add css files for the fonts to the css folder of the template instead of scss files which need to be compiled? |
If I could chose, I would make css and put them into a folder "templates/cassiopeia/css/fonts" and remove the "font--" prefix from their name. Only thing what I don't know is if it needs the step to compile from scss to css for some reason. If that is the case, then I would put the scss files into a folder "templates/cassiopeia/scss/fonts" and also remove the "font--" prefix from their name, and let the script use that folder in the "folders" array and not the single files in the "files" array. |
… to the css compile script (#23) * Rename templates/cassiopeia/scss/font--josefin-sans.scss to templates/cassiopeia/scss/fonts/josefin-sans.scss * Rename templates/cassiopeia/scss/font--montserrat.scss to templates/cassiopeia/scss/fonts/montserrat.scss * Fix PHP and SCSS code style * More PHP code style * Finish the sub folder move * Add fonts scss to the compile script
I've solved it so far. The only question which remains is the one in my review comment above: @drmenzelit Could you check and comment? |
This is not extensible. Either use scss or css. The nice thing about scss is it does allow for the base to be a $var which makes it a single point of change for end-users. in /css you want in /fonts you want only your .ttf & .woff/woff2 files. |
- Move the fonts abd their scss to `build/media_source/fonts` - Modify the the css build script so it copies the fonts and the compiled css to `media/fonts`. - Use a `filelist` field for selecting the fonts => No need to edit `templateDetails.xml` anymore for adding new fonts. - Dynamically register the asset so no need to edit `joomla.asset.json` anymore for adding new fonts.
templates/cassiopeia/index.php
Outdated
// Template path | ||
$templatePath = Uri::root() . 'templates/'.$this->template; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drmenzelit Do you know if we need this variable? It was added with the first version of the Google Fonts here on this branch. I see it nowhere used now in template.php.
Removed Montserrat / Work Sans combination and added Fira Sans as is in Cassiopeia v1.
When I open the template style options after a new installation, I see the Google Fonts option is already switched on, and fira-sans is selected. But the frontpage doesn't use that unless I save the template style options, without having changed anything else. After that first saving, everything works well. I think it is because the default value of the switcher as defined in the form XML is not equal to what you get in the PHP code when that configuration value is not set. I'll see if I can fix it, I have an idea. |
@richard67 that means its not being defined in the installation sql |
@brianteeman Should it be, or could we use |
It should be in the sql |
Hmm installation SQL is easy, but making an update SQL to update older 4.0 Betas would maybe be too risky, with search and replace in the options. I have to think about that. |
on a fresh install the default used in the xml is what is set in the db as a param. After the 1st save then it changes to whatever the values in the template are. There's no need to have a value preset in a sql file. |
@N6REJ Sorry Troy, but it seems you did not get the problem. When you make a new installation and you do not do anything in backend and you go to the site, the template checks the result of If you now go to backend and check the settings without saving, you will see that the google fonts are swiched on and a font is selected, which does not fit to what you get in the frontent, There are 2 ways out: 1. Init in db, and 2. using We had this problem at other places, too, and one of the 2 ways or both have been used to solve it, and we still have it at other places where it was not really solved. I think that's a weak point in design that we define the default values in a way which is not available if not using the form. |
If as a matter of best practice we get in the habit of always writing the defaults in the xml it will resolve a lot of problems as this "issue" keeps coming up. Personally I would not care about beta to beta upgrades for this |
Really "xml"? Or should it have been "sql" and the spell checker "corrected" it?
Me neither. We have broken it anyway with the child templates |
not enough coffee yet. it was of course sql |
Update: Forget it, we can't do that. One may alrerady have changed some of the params and will complain if that is reset with an update. |
Am merging into the development branch for now. For further improvements please make pull requests against the development branch. |
Pull Request for Issue #14 #15 .
Summary of Changes
Added parameter(s) for GoogleFonts.
Example fonts installed.
Removed Fira Sans
Testing Instructions
Open template, you will see two new parameters
Google Font yes / no
Google Font Name as select field
Expected result
If "no" is selected the template will use the font definitions from BS4 (at the moment)
If "yes" you can select a font or font combination. The selected font will be loaded with a specific css file.
Documentation Changes Required
We need to explain how to install and use other fonts
Update 2020-08-21 by @richard67
There are 2 use cases.
Case 1: CMS contibutors add new fonts to the sources so they are shipped with the CMS.
This should not really happen often since we should at the end ship only the fonts which are really used by the CMS, maybe a choice of 2 which look nice, but not a lot.
Upload a scss file for each font or combination of fonts and corresponding woff and woff2 files to folder
/build/media_source/fonts
and then runnpm ci
. That's it.Compiled css and copied font files will be availabe in folder
/media/fonts
after that.In the source code only what has changed or been added in folder
/build/media_source/fonts
has to be checked in.Case 2: Users add new fonts to an installlled J4.
Upload a css file for each font or combination of fonts and corresponding woff and woff2 files to folder
/media/fonts
. Optionally you can also upload the minified css file in addition. That's it.In both cases, after you have done the above steps (either case 1 or case 2), you can select in backend in Cassiopeia's template style settings the new fonts by the base name of the css files in the
/media/fonts
folder. Minified css files will be ignored.