[英]Typo3 Custom Extensions
I am all new to Typo3. 我是Typo3的新手。 I created an extension called myExtension in /typo3conf/ext/myExtension
我在/ typo3conf / ext / myExtension中创建了一个名为myExtension的扩展
The folder structure is as follows 文件夹结构如下
-Classes
--ViewHelpers
--myExtensionViewHelper.php
-Resources
--Resources
--Private
--Templates
--myExtension
--index.html
myExtensionViewHelper.php has the following code myExtensionViewHelper.php具有以下代码
<?php
/**
* This class is a demo view helper for the Fluid templating engine.
*
* @package TYPO3
* @subpackage Fluid
* @version
*/
class Tx_myExtension_ViewHelpers_myExtensionViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
/**
* Renders some classic dummy content: Lorem Ipsum...
*
* @param int $length The number of characters of the dummy content
* @validate $length IntegerValidator
* @return string dummy content, cropped after the given number of characters
*/
public function render($length) {
$dummyContent = 'Lorem ipsum dolor sit amet.';
return substr($dummyContent, 0, $length);
}
}
?>
the index.html file contains index.html文件包含
{namespace myExtension=Tx_myExtension_ViewHelpers}
<f:layout name="Default" />
<f:section name="content">
<h1>
<myExtension:myExtension length="5" />
</h1>
</f:section>
In my typo3 backend, I created a page called "Mango" and included this plugin to it. 在我的typo3后端中,我创建了一个名为“ Mango”的页面,并将此插件包含在其中。
I have a template, layout and template.html for the webpage "Mango". 我有一个针对“芒果”网页的模板,布局和template.html。
Now what should I do to get the output of the file Index.html into this page? 现在我该怎么做才能将Index.html文件的输出输入到此页面?
Am I doing this right ? 我这样做对吗? I haven't done anything else other than the stuff mentioned here.
除了这里提到的东西以外,我没有做过其他任何事情。
I'm totally new to Typo3 and all this is a little hard to understand. 我对Typo3完全陌生,所有这些都有点难以理解。 Please do mention even if anything is trivial and obvious.
即使有任何琐碎且显而易见的事情,也请提及。
Thanks :) 谢谢 :)
You need a controller which loads the template system and displays the template. 您需要一个控制器来加载模板系统并显示模板。 The ViewHelper you have defined is not required to get a result, these are just custom template classes you can use in your templates.
您不需要定义ViewViewer即可获得结果,这些只是可以在模板中使用的自定义模板类。
Controller Example: 控制器示例:
File: Classes/Controller/TestController.php 文件:Classs / Controller / TestController.php
class Tx_MyExtension_Controller_TestController extends Tx_Extbase_MVC_Controller_ActionController {
/**
* action sampleAction
*
* @return void
*/
public function sampleAction() {
//Add variables to template
$this->view->assign("sample_var", "sample value");
}
}
Now you need a template file which is in a directory based on the Controller and Action. 现在,您需要一个模板文件,该文件位于基于Controller和Action的目录中。 So in this sample you need a template file in
my_extension/Resources/Private/Templates/Test/
(where "Test" is the Controller name) which is called like the action Sample.html
. 因此,在此示例中,您需要
my_extension/Resources/Private/Templates/Test/
的模板文件(其中“ Test”是控制器名称),该文件的名称类似于操作Sample.html
。
To get a wrap around your extension you also need the Layout file my_extension/Resources/Private/Layouts/Default.html
with the content 要扩展您的扩展程序,还需要布局文件
my_extension/Resources/Private/Layouts/Default.html
及其内容
<div class="tx-my-extension">
<f:render section="main" />
</div>
This file is called with <f:layout name="Default" />
in your template and <f:render section="main" />
is the place the content will be displayed. 该文件在模板中以
<f:layout name="Default" />
调用,而<f:render section="main" />
是显示内容的位置。
Next step is to allow the action in the extension. 下一步是允许扩展中的操作。 Go to your
ext_localconf.php
in the root directory and add 转到根目录中的
ext_localconf.php
并添加
Tx_Extbase_Utility_Extension::configurePlugin(
$_EXTKEY,
'Myextension',
array(
'Test' => 'sample', // 'ControllerName' => 'ActionName, OtherAction'
),
// non-cacheable actions
array(
'Test' => 'sample', // 'ControllerName' => 'ActionName, OtherAction'
)
);
Last step is to create the template file my_extension/Resources/Private/Templates/Test/Sample.html
with the content 最后一步是使用内容创建模板文件
my_extension/Resources/Private/Templates/Test/Sample.html
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<f:layout name="Default" />
<f:section name="main">
Your sample var: {sample_var}
</f:section>
Now you should see the result after adding the Plugin to a page. 现在,将插件添加到页面后,您应该会看到结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.