Who can tell me how to change the link from PHP.
$this->pageConfig->addPageAsset('')
I already tried but not working.
$this->getUrl('https://...')
Thank you!
Who can tell me how to change the link from PHP.
$this->pageConfig->addPageAsset('')
I already tried but not working.
$this->getUrl('https://...')
Thank you!
You can use this code to add css
file on your phtml
file.
<link rel="stylesheet" type="text/css" href="YOURCSSURL" />
I would try to add this method on your block template :
protected function _prepareLayout()
And then customise your metadata as you want in there. But this is the same thing as updating directly the phtml file as mentionned by @Dhiren Vasoya
To include an external CSS file from xml, add
https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/css-topics/css-themes.html
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<css src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css" src_type="url" rel="stylesheet" type="text/css" />
</head>
</page>
To include an external CSS file from php
Step 1 – Create a block class in your module
use Magento\Framework\View\Element\Template;
class Head extends Template
{
/**
* @var \Magento\Framework\View\Asset\Repository
*/
protected $assetRepository;
/**
* Header constructor.
* @param Template\Context $context
* @param array $data
*/
public function __construct(
Template\Context $context,
array $data = []
)
{
parent::__construct($context, $data);
$this->assetRepository = $context->getAssetRepository();
}
/**
* @return string
*/
public function getUrlCSS()
{
$asset_repository = $this->assetRepository;
$asset = $asset_repository->createAsset('URL to External Source');
$url = $asset->getUrl();
return $url;
}
}
Step 2 – Create corresponding phtml for the class created in Step 1
$url = $block->getUrlCSS();
if ($url):
echo '<link rel="stylesheet" type="text/css" media="all" href="'.$block->getUrlCSS().'" />'
endif;
Step 3 – Create layout xml file to call the above phtml file in the head section of your website under