PHPackages                             anibalsanchez/extly-html-asset-tags-builder - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. anibalsanchez/extly-html-asset-tags-builder

ActiveLibrary

anibalsanchez/extly-html-asset-tags-builder
===========================================

The Asset Tags Builder manages the generation of script and style tags for an Html Document.

2.0.0(6mo ago)01.2k1MITPHPPHP ^8.0

Since Aug 7Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/anibalsanchez/extly-html-asset-tags-builder)[ Packagist](https://packagist.org/packages/anibalsanchez/extly-html-asset-tags-builder)[ RSS](/packages/anibalsanchez-extly-html-asset-tags-builder/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (2)Versions (25)Used By (0)

HTML Asset Tags Builder
=======================

[](#html-asset-tags-builder)

Description
-----------

[](#description)

Beyond the JDocument, the Asset Tags Builder manages the generation of script and style tags for an Html Document.

`composer require anibalsanchez/extly-html-asset-tags-builder`

Usage
-----

[](#usage)

### Create your Asset Tags Repository

[](#create-your-asset-tags-repository)

```
require_once JPATH_ROOT.'/libraries/my-library/vendor/autoload.php';

use Extly\Infrastructure\Support\HtmlAsset\Repository as HtmlAssetRepository;

// Create the repository, where all tags are defined and stored before the rendering
$htmlAssetRepository = HtmlAssetRepository::getInstance();
```

### Including scripts and styles

[](#including-scripts-and-styles)

The tags builder has the following predefined ways to include these scripts and styles:

- InlineScriptTag
- InlineStyleTag
- LinkCriticalStylesheetTag
- LinkDeferStylesheetTag
- ScriptTag

For instance, `ScriptTag` defers the script and the `LinkDeferStylesheetTag` loads the stylesheet with a script at the end of the body.

Sample code:

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

### Head and Body Renderers for Joomla

[](#head-and-body-renderers-for-joomla)

These classes help to define the proper renderers for the head and body scripts. In the template, they are called in this way:

Statement to generate the scripts and styles for the document head:

```

```

Statement to generate the scriptsat the bottom of the document body:

```

```

#### Head Renderer

[](#head-renderer)

```
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 `` 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;
    }
}
```

#### Body Renderer

[](#body-renderer)

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

Acknowledgements
----------------

[](#acknowledgements)

- Inspired by PrestaShop `JavascriptManager`
- [JAB18 - Let’s build a Joomla PWA PWS website](https://www.youtube.com/watch?v=Hg_ATQEl9_U&list=PLE_ZsP4SqZpynn-n0q1G8iUaeGYaqVF4k)

License
-------

[](#license)

The MIT License (MIT)

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance69

Regular maintenance activity

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~108 days

Recently: every ~484 days

Total

22

Last Release

184d ago

Major Versions

1.10.0 → 2.0.02025-11-10

PHP version history (3 changes)1.0.0PHP &gt;=5.6.0

1.9.0PHP ^7.3 || ^8.0

2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/df7fbcf5652e2a22940918d3c4db48cfaadd50c9096fd7ccd46504d62eb6fd07?d=identicon)[anibal.sanchez](/maintainers/anibal.sanchez)

---

Top Contributors

[![anibalsanchez](https://avatars.githubusercontent.com/u/385780?v=4)](https://github.com/anibalsanchez "anibalsanchez (68 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/anibalsanchez-extly-html-asset-tags-builder/health.svg)

```
[![Health](https://phpackages.com/badges/anibalsanchez-extly-html-asset-tags-builder/health.svg)](https://phpackages.com/packages/anibalsanchez-extly-html-asset-tags-builder)
```

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
