Joomla 4 不加载自定义模板的资源

问题描述 投票:0回答:1

我为 Joomla 4 创建了一个简单的模板:

*.zip
的结构:

  • index.php
  • joomla.asset.json
  • templateDetails.xml
  • media/
    • css/
      • template.css
      • template.min.css
    • images/
      • brand.png
      • favicon.ico
    • js/
      • template.js
      • template.min.js

index.php:

<?php

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;

$app = Factory::getApplication();
$wa  = $this->getWebAssetManager();

// Add Favicon from images folder
$this->addHeadLink(HTMLHelper::_('image', 'favicon.ico', '', [], true, 1), 'icon', 'rel', ['type' => 'image/x-icon']);

// Detecting Active Variables
$sitename = htmlspecialchars($app->get('sitename'), ENT_QUOTES, 'UTF-8');

// Get this template's path
$templatePath = 'templates/' . $this->template;

//Register our web assets (Css/JS)
$wa->useStyle('template.tofu.mainstyles');
$wa->useStyle('template.tofu.user');
$wa->useScript('template.tofu.scripts');

//Set viewport
$this->setMetaData('viewport', 'width=device-width, initial-scale=1');

$logo = HTMLHelper::_('image', 'brand.png', $sitename, ['class' => 'd-inline-block align-text-top', 'width' => '32', 'height' => '32', 'loading' => 'eager'], true, 0);

?>
<!DOCTYPE html>

<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "<?php echo $this->language; ?>" lang = "<?php echo $this->language; ?>" dir="<?php echo $this->direction; ?>">

   <head>
      <jdoc:include type="metas" />
      <jdoc:include type="styles" />
      <jdoc:include type="scripts" />
   </head>

   <body>
      <div class="container">
         <header>
            <nav class="navbar navbar-light bg-light">
               <div class="container-fluid">
                  <a class="navbar-brand" href="#">
                     <?php echo $logo; ?>
                     <?php echo $sitename ?>
                  </a>
               </div>
            </nav>
         </header>
         <jdoc:include type = "modules" name = "top" />
         <jdoc:include type = "component" />
         <jdoc:include type = "modules" name = "bottom" />
      </div>
      <!-- Include any debugging info -->
       <jdoc:include type="modules" name="debug" style="none" />
   </body>
    
</html>

templateDetails.xml:

<?xml version = "1.0" encoding = "UTF-8"?>

<extension type="template" client="site" method="upgrade">
   <name>tofu</name>
   <creationDate>2023-06-12</creationDate>
   <author>Denis Sologub</author>
   <authorEmail></authorEmail>
   <authorUrl>https://mysite.ru</authorUrl>
   <copyright>@ My site. All rights reserved</copyright>
   <license>MIT</license>
   <version>1.3</version>
   <description>Light theme for Joomla</description>
    
   <files>
      <filename>index.php</filename>
        <filename>joomla.asset.json</filename>
      <filename>templateDetails.xml</filename>
   </files>

   <media destination="templates/site/tofu" folder="media">
        <folder>js</folder>
        <folder>css</folder>
        <folder>images</folder>
    </media>
    
   <positions>
      <position>breadcrumb</position>
      <position>left</position>
      <position>right</position>
      <position>top</position>
      <position>user1</position>
      <position>user2</position>
      <position>user3</position>
      <position>user4</position>
      <position>footer</position>
   </positions>
    
</extension>

joomla.asset.json:

{
  "$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json",
  "name": "tofu",
  "version": "4.0.0",
  "description": "This file contains details of the assets used by Tofu, the default Joomla 4 site template.",
  "license": "MIT",
  "assets": [
    {
      "name": "template.tofu.mainstyles",
      "description": "The default css style to use.",
      "type": "style",
      "uri": "template.min.css"
    },
    {
      "name": "template.tofu.user",
      "description": "The custom css style to use. Must be placed in media/templates/site/j4starter/css/user.css",
      "type": "style",
      "uri": "",
      "dependencies": [
        "template.tofu.mainstyles"
      ]
    },
    {
      "name": "template.tofu.scripts",
      "description": "The file containing the javascript for this template.",
      "type": "script",
      "uri": "template.min.js",
      "attributes" : {
        "defer": true
      },
      "dependencies": [
        "core"
      ]
    },
    {
      "name": "template.active",
      "description": "A dummy asset to allow extensions to use it as a dependency to the active template.",
      "type": "script",
      "uri": "",
      "dependencies": [
        "template.tofu.scripts"
      ]
    }
  ]
}

安装 Joomla 4 后,将模板的所有文件放入正确的文件夹中:

  • templates/tofu/
  • media/templates/site/tofu/

但是它不会加载我的资源:

<!DOCTYPE html>

<html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "ru-ru" lang = "ru-ru" dir="ltr">

   <head>
      <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Some description">
    <meta name="generator" content="Joomla! - Open Source Content Management">
    <title>Home</title>
    <link href="/index.php?format=feed&amp;type=rss" rel="alternate" type="application/rss+xml" title="Home">
    <link href="/index.php?format=feed&amp;type=atom" rel="alternate" type="application/atom+xml" title="Home">
    <link href="/media/system/images/favicon.ico" rel="icon" type="image/x-icon">

      
      <script type="application/json" class="joomla-script-options new">{"system.paths":{"root":"","rootFull":"https:\/\/mysite.ru\/","base":"","baseFull":"https:\/\/mysite.ru\/"},"csrf.token":"b74ed1eb5b2faea874f3b332eb276f28"}</script>
    <script src="/media/system/js/core.min.js?576eb51da909dcf692c98643faa6fc89629ead18"></script>

   </head>

   <body>
      <div class="container">
         <header>
            <nav class="navbar navbar-light bg-light">
               <div class="container-fluid">
                  <a class="navbar-brand" href="#">
                     <img class="d-inline-block align-text-top" width="32" height="32" loading="eager" src="/" alt="My site">                     My site                  </a>
               </div>
            </nav>
         </header>
         <jdoc:include type = "modules" name = "top" />
         <jdoc:include type = "component" />
         <jdoc:include type = "modules" name = "bottom" />
      </div>
      <!-- Include any debugging info -->
       
   </body>
    
</html>
php html joomla joomla-template joomla4
1个回答
0
投票

Cassiopeia 模板显示这是可能的,但模板需要“可继承”或至少在 templateDetails.xml 中具有

<inheritable>1</inheritable>

您需要删除模板并重新安装,该选项才会生效。仅添加标签并更新似乎没有什么区别。

© www.soinside.com 2019 - 2024. All rights reserved.