I am in the process of writing a custom theme for a client and am having issues with the Web Asset Manager. I have been following examples of other templates that are built for Joomla 4+, but I must be doing something incorrectly as the defined template CSS and JS files are not being loaded into the template's index file.
index.php - Simplified for readability
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Menu\SiteMenu;
$app = Factory::getApplication();
$wa = $this->getWebAssetManager();
/**
* Load template style and functionality assets
*
*/
$wa->useStyle( 'template.[redacted]' )
->useScript( 'template.[redacted]' );
<!DOCTYPE html>
<html lang="<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">
<head>
<jdoc:include type="metas" />
<jdoc:include type="styles" />
<jdoc:include type="scripts" />
</head>
templateDetails.xml
<?xml version="1.0" encoding="UTF-8"?>
<extension version="4.0" type="template" client="site">
<name>[redacted]</name>
<version>1.0.0</version>
<creationDate>2023-10-17</creationDate>
<author>Mike Hermary</author>
<authorEmail>[email protected]</authorEmail>
<authorUrl>https://imaginecreative.ca</authorUrl>
<description>Joomla 4 template for [redacted]</description>
<copyright>Copyright 2007 - Now Imagine Creative. All rights reserved.</copyright>
<files>
<filename>index.php</filename>
<filename>joomla.asset.json</filename>
<filename>templateDetails.xml</filename>
</files>
<languages folder="language">
<language tag="en-GB">en-GB/tpl_[redacted].ini</language>
<language tag="en-GB">en-GB/tpl_[redacted].sys.ini</language>
</languages>
<media destination="templates/site/[redacted]" folder="media">
<folder>css</folder>
<folder>scss</folder>
<folder>images</folder>
<folder>js</folder>
</media>
<positions>
<position></position>
</positions>
</extension>
joomla.asset.json
{
"$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json",
"name": "[redacted]",
"version": "4.0.0",
"description": "This file contains details of the assets used by [redacted]",
"license": "GPL-2.0-or-later",
"assets": [
{
"name": "template.[redacted]",
"description": "The file containing the CSS for this template.",
"type": "style",
"uri": "template.min.css"
},
{
"name": "template.[redacted]",
"description": "The file containing the JavaScript for this template.",
"type": "script",
"uri": "template.js",
"attributes" : {
"type": "module"
}
}
]
}
The assets media directory exists in the template and in the media/templates/site/<template_name>
directory on the server.
I am using Git to push the files to the template directory. The ownership for the template directory is git:git
. I tried changing to www-data:www-data
for testing purposes, but it did not help.
The asset files in the media/templates/site/<template_name>
directory are using www-data:www-data
.
Any suggestions on what I do not have setup correctly.