The correct answer is to create a new AssetBundle.
While you can directly put HTML code for fonts in the main.php file, this is not the Yii path. If you tried to load jQuery files this way, you might notice strange behavior when you directly enter them in HTML.
For example: Directly place the HTML tag for the Bootstrap CDN at the head of your main.php. Then, somewhere in your code, try using a tooltip. You will receive an error message in the console that the tooltip is not a function. - This is due to the fact that Yii puts all of your template files together, and Bootstrap is not available at the time.
While just downloading the font probably won't cause any problems, it is a good idea to do the way they were intended. Following the rules of MVC, document your code correctly and following the recommendations of Yii, you will go a long way. You will not only thank yourself a year later when you have to return to the project, but the next guy will appreciate it. I cannot stand on systems and see things thrown everywhere, chincy hacks and spaghetti code, as well as documentation or comments.
The right way:
Create a new AssetBundle. In your assets folder, you probably already have AppAsset.php . Duplicate it and name it FontAsset.php .
Here is an example from my project using 3 Google fonts.
FontAsset.php
<?php namespace app\assets; use yii\web\AssetBundle; class FontAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ '//fonts.googleapis.com/css?family=Open+Sans:400,700', '//fonts.googleapis.com/css?family=Ubuntu:400,700', '//fonts.googleapis.com/css?family=Oswald:400,700' ]; public $cssOptions = [ 'type' => 'text/css', ]; }
In your layout, for example main.php. Right below where you see AppAsset::register($this)
main.php
use app\assets\FontAsset; FontAsset::register($this);
For each layout file that you want to download these fonts, enable FontAsset.
AssetBundle is basically a collection of CSS and / or JS files and options. You can add another to say that JWPlayer said what is called VideoAsset, and add JS / CSS files for JWPlayer to it.
Point, you should not add these things directly to HTML layouts directly, as this can cause problems. Let AssetManager process them by declaring AssetBundles.
It can save you later on the road!