简体   繁体   English

TYPO3 Extbase后端模块。 模板路径问题

[英]TYPO3 Extbase backend module. Template path issue

I'm experiencing a strange problem with extbase/fluid extension creation. 我在使用extbase / fluid扩展创建时遇到了一个奇怪的问题。 I use TYPO3 6.1 我使用TYPO3 6.1

I've made an extension with a backend module on my dev server (same configuration/hardware then the prod). 我在我的开发服务器上使用后端模块进行了扩展(与prod相同的配置/硬件)。 The module works perfectly with the path to the template : 该模块与模板的路径完美配合:

myext/Resources/Private/Backend/Templates myext /资源/个人/后端/模板
myext/Resources/Private/Backend/Layouts myext /资源/个人/后端/布局
myext/Resources/Private/Backend/Partials myext /资源/个人/后端/局部模板

After this, I downloaded my extension's zip in the ext manager and then installer on the prod server. 在此之后,我在ext管理器中下载了我的扩展名zip,然后在prod服务器上下载了安装程序。 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 /资源/个人/模板
myext/Resources/Private/Layouts myext /资源/个人/布局
myext/Resources/Private/Partials myext /资源/私有/局部模板

With this it works, but in the module configuration, I specify the right path to the "Backend/" folder. 使用它可以工作,但在模块配置中,我指定了“Backend /”文件夹的正确路径。

I wont to move my folder in the Private folder, I want it to run in the Private/Backend folder. 我不会在Private文件夹中移动我的文件夹,我希望它在Private / Backend文件夹中运行。

I've included the extension static template to the website root TS template. 我已将扩展静态模板包含在网站根TS模板中。

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. 主要问题是,如果根路径中没有模板,则不会在存储文件夹或页面上加载typoscript配置。

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. 解释:你将为扩展设置的typoscript配置,它是在ext_typoscript_setup,静态模板或通过php,它总是需要在页面根目录的某个地方的系统记录模板。 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. 否则它将不会被渲染 - 并且不会发生extbase扩展的路径设置,因此设置了默认布局,模板和部分路径,这就是脚本将查找内容的位置。

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 我希望这有助于greetz benji

As @benjamin-kott explains, TYPO3's backend modules configurations need to be loaded first. 正如@ benjamin-kott解释的那样,需要首先加载TYPO3的后端模块配置。 Unfortunately, extension's typoscript files are not automatically loaded by default. 不幸的是,默认情况下不会自动加载扩展程序的typoscript文件。

One way of make TYPO3 aware of this typoscript files is creating two files in extension's root folder: 让TYPO3知道这个typoscript文件的一种方法是在扩展的根文件夹中创建两个文件:

  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. 您可以使用TypoScript对象浏览器来确定是否正在加载您的设置和常量。

I dont realy know ur setup, but normaly you must setup these paths in /Configuration/TypoScript/setup.txt like this 我真的不知道你的设置,但是你必须在/Configuration/TypoScript/setup.txt中设置这些路径,就像这样

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 您还应该将这些行添加到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. 虽然这个帖子很老,但我想向大家展示我对TYPO3 7.6 LTS的解决方案。

First you need to include your TypoScript files via Template > Edit whole record > Includes . 首先,您需要通过Template > Edit whole record > Includes来包含TypoScript文件。

And in your TypoScript you need to use templateRootPaths.0 instead of templateRootPath : 在TypoScript中,您需要使用templateRootPaths.0而不是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/
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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