简体   繁体   中英

TYPO3 Extbase backend module. Template path issue

I'm experiencing a strange problem with extbase/fluid extension creation. I use TYPO3 6.1

I've made an extension with a backend module on my dev server (same configuration/hardware then the prod). The module works perfectly with the path to the template :

myext/Resources/Private/Backend/Templates
myext/Resources/Private/Backend/Layouts
myext/Resources/Private/Backend/Partials

After this, I downloaded my extension's zip in the ext manager and then installer on the prod server. Now I can't use my extension because the module don't find the templates. I've configured the extension by the same way. The templates are in the right path.

I test to move my folder to the parent level :

myext/Resources/Private/Templates
myext/Resources/Private/Layouts
myext/Resources/Private/Partials

With this it works, but in the module configuration, I specify the right path to the "Backend/" folder.

I wont to move my folder in the Private folder, I want it to run in the Private/Backend folder.

I've included the extension static template to the website root TS template.

Here's the constants :

module.tx_myext {
    view {
        # cat=module.tx_myext/file; type=string; label=Path to template root (BE)
        templateRootPath = EXT:wng_myext/Resources/Private/Backend/Templates/
        # cat=module.tx_myext/file; type=string; label=Path to template partials (BE)
        partialRootPath = EXT:wng_myext/Resources/Private/Backend/Partials/
        # cat=module.tx_myext/file; type=string; label=Path to template layouts (BE)
        layoutRootPath = EXT:wng_myext/Resources/Private/Backend/Layouts/
    }
    persistence {
        # cat=module.tx_myext//a; type=string; label=Default storage PID
        storagePid =
    }
}

And here's the setup :

module.tx_myext {
    persistence {
        storagePid = {$module.tx_myext.persistence.storagePid}
    }
    view {
        templateRootPath = {$module.tx_myext.view.templateRootPath}
        partialRootPath = {$module.tx_myext.view.partialRootPath}
        layoutRootPath = {$module.tx_myext.view.layoutRootPath}
    }
}

The main problem will be that the typoscript configurations will not get loaded on storage folders or pages without an template in the root path.

Explaination: typoscript configuration you will set for your extension wether it is in ext_typoscript_setup, an static template or via php it will always need an system record template somewhere in the root of the page. otherwise it will not get rendered - and no path settings for your extbase extensions will happen, so the default layout, template and partial path is set and thats the place the script will look for your stuff.

Default is:

/Private/Resources/Layout/
/Private/Resources/Partials/
/Private/Resources/Templates/@Controllername/@Actionname

if you need to override these for your backendmodule you can work around that problem by injecting the settings for the view directly in your controller.

<?php
namespace VendorKey\ExtensionName\Controller;

class SettingsController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

/**
 * Initializes the controller before invoking an action method.
 * @return void
 */
protected function initializeAction() {
    $this->setBackendModuleTemplates();
}

/**
 * Set Backend Module Templates
 * @return void
 */
private function setBackendModuleTemplates(){
    $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
    $viewConfiguration = array(
        'view' => array(
            'templateRootPath' => 'EXT:extension_name/Resources/Private/Templates/Modules/',
            'partialRootPath' => 'EXT:extension_name/Resources/Private/Partials/Modules/',
            'layoutRootPath' => 'EXT:extension_name/Resources/Private/Layouts/Modules/',
        )
    );
    $this->configurationManager->setConfiguration(array_merge($frameworkConfiguration, $viewConfiguration));        
}

/**
 * action settings
 * @return void
 */
public function settingsAction(){

}

}

i hope this helps greetz benji

As @benjamin-kott explains, TYPO3's backend modules configurations need to be loaded first. Unfortunately, extension's typoscript files are not automatically loaded by default.

One way of make TYPO3 aware of this typoscript files is creating two files in extension's root folder:

  1. ext_typoscript_constants.txt

     <INCLUDE_TYPOSCRIPT: source="FILE:EXT:myext/Configuration/TypoScript/constants.txt"> 
  2. ext_typoscript_setup.txt

     <INCLUDE_TYPOSCRIPT: source="FILE:EXT:myext/Configuration/TypoScript/setup.txt"> 

(kind of obvious but: you should replace this paths with yours)

After adding this files, you should reinstall the extension to see changes. You can use the TypoScript Object Browser to find out if your setup and constants are being loaded.

I dont realy know ur setup, but normaly you must setup these paths in /Configuration/TypoScript/setup.txt like this

module.tx_yourext {
    persistence {
        storagePid = {$pid}
    }
    view {
        templateRootPath = {$templateRootPath}
        partialRootPath = {$partialRootPath}
        layoutRootPath = {$layoutRootPath}
    }
}

This configuration does not being used until you add the static template of your extension. Also you should add these lines to the ext_tables.php

if (TYPO3_MODE === 'BE') {
    Tx_Extbase_Utility_Extension::registerModule(
        $_EXTKEY,
        'web',          // Main area
        'mod1',         // Name of the module
        '',             // Position of the module
        array(          // Allowed controller action combinations
            'Controller' => 'actionName'
        ),
        array(          // Additional configuration
            'access'    => 'user,group',
            'icon'      => 'EXT:my_ext/ext_icon.gif',
            'labels'    => 'LLL:EXT:' . $_EXTKEY . '/Resources/Private/Language/locallang_mod.xml',
        )
    );
}

尝试清理所有缓存,即使在typo3temp / Core / Cache(或类似的东西)

Although this thread is quite old I want to show you guys my solution for TYPO3 7.6 LTS.

First you need to include your TypoScript files via Template > Edit whole record > Includes .

And in your TypoScript you need to use templateRootPaths.0 instead of templateRootPath :

module.tx_extension {
    view {
        templateRootPaths.0 = EXT:extension/Resources/Private/Backend/Templates/
        partialRootPaths.0 = EXT:extension/Resources/Private/Backend/Partials/
        layoutRootPaths.0 = EXT:extension/Resources/Private/Backend/Layouts/
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM