<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
anibalsanchez / extly-html-asset-tags-builder example snippets
use Extly\Infrastructure\Support\HtmlAsset\Repository as HtmlAssetRepository;
// Create the repository, where all tags are defined and stored before the rendering
$htmlAssetRepository = HtmlAssetRepository::getInstance();
use Extly\Infrastructure\Support\HtmlAsset\Asset\InlineScriptTag;
use Extly\Infrastructure\Support\HtmlAsset\Asset\LinkCriticalStylesheetTag;
use Extly\Infrastructure\Support\HtmlAsset\Asset\LinkDeferStylesheetTag;
use Extly\Infrastructure\Support\HtmlAsset\Asset\ScriptTag;
// Add template js
$templateJsFile = CMSHTMLHelper::script('template.js', ['relative' => true, 'pathOnly' => true]);
$templateJsFile = $templateJsFile.'?'.(new JVersion)->getMediaVersion();
$htmlAssetRepository->push(new ScriptTag($templateJsFile));
// Add Stylesheets
$templateCssFile = CMSHTMLHelper::stylesheet('template.css', ['relative' => true, 'pathOnly' => true]);
$templateCssFile = $templateCssFile.'?'.(new JVersion)->getMediaVersion();
$htmlAssetRepository->push(new LinkCriticalStylesheetTag($templateCssFile));
// Additional inline head scripts
$headScripts = $this->params->get('headScripts');
if (!empty($headScripts)) {
$htmlAssetRepository->push(new InlineScriptTag($headScripts));
}
// FontAwesome at the end of the body
$linkStylesheetTag = new LinkDeferStylesheetTag('https://use.fontawesome.com/releases/v5.6.3/css/all.css');
$htmlAssetRepository->push($linkStylesheetTag);
<jdoc:
<jdoc:
namespace Joomla\CMS\Document\Renderer\Html;
defined('JPATH_PLATFORM') or die;
use Extly\Infrastructure\Support\HtmlAsset\HtmlAssetTagsBuilder;
use Extly\Infrastructure\Support\HtmlAsset\Repository;
/**
* HTML document renderer for the document `<head>` element.
*/
class XTHtmlAssetsRenderer extends HeadRenderer
{
/**
* Renders the document head and returns the results as a string.
*
* @param string $head (unused)
* @param array $params Associative array of values
* @param string $content The script
*
* @return string The output of the script
*/
public function render($head, $params = [], $content = null)
{
$document = $this->_doc;
// Nothing loaded by default
$document->_styleSheets = [];
$document->_style = [];
$document->_scripts = [];
$document->_script = [];
// My Script and Styles
$headScript = new HtmlAssetTagsBuilder()->generate(Repository::GLOBAL_POSITION_HEAD);
return parent::render($head, $params, $content).$headScript;
}
}
namespace Joomla\CMS\Document\Renderer\Html;
defined('JPATH_PLATFORM') or die;
use Extly\Infrastructure\Support\HtmlAsset\HtmlAssetTagsBuilder;
use Extly\Infrastructure\Support\HtmlAsset\Repository;
/**
* HTML document renderer for the document `<head>` element.
*/
class XTHtmlAssetsBodyRenderer extends HeadRenderer
{
/**
* Renders the document head and returns the results as a string.
*
* @param string $head (unused)
* @param array $params Associative array of values
* @param string $content The script
*
* @return string The output of the script
*/
public function render($head, $params = [], $content = null)
{
return new HtmlAssetTagsBuilder()->generate(Repository::GLOBAL_POSITION_BODY);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.