[英]Creating ViewHelpers inside Typo3 fluid template
I want to build a Typo3 template from scratch using Fluid. 我想使用Fluid从头开始构建Typo3模板。 I'm new to this CMS, but have knowledge in Zend Framework which uses a similar MVC approach. 我是这个CMS的新手,但是对使用类似MVC方法的Zend Framework有所了解。 What I don't know is where to put the ViewHelpers inside my template. 我不知道将ViewHelpers放在模板中的什么位置。
I have the following directory structure: 我有以下目录结构:
typo3/fileadmin/
projectname/
templates/
assets/
images
js
styles/
css/
less/
layouts/
single.html
2col.html
3col.html
partials/
breadcrumb.html
default.html
tsconfig/
typoscript/
constants.ts
setup.ts
All I found on the web were tutorials using Fluid inside a Typo3 extension. 我在网上发现的所有内容都是在Typo3扩展程序中使用Fluid的教程。 I'd like to register a new namespace for my classes, define a directory for the autoloader and use the viewhelpers inside my templates and not inside an extension (eg <my:formatMyWay>
) 我想为我的类注册一个新的名称空间,为自动加载器定义一个目录,并在模板内而不是扩展内使用viewhelpers(例如<my:formatMyWay>
)
Is there something similar inside the templates? 模板内部是否有类似内容? Or do I have to create my own Typo3 extension for this? 还是我必须为此创建自己的Typo3扩展?
You're right, you have to create your own TYPO3 extension in order to have own viewhelpers. 没错,您必须创建自己的TYPO3扩展名才能拥有自己的viewhelper。 You can use the extension_builder to kickstart an empty extension. 您可以使用extension_builder来启动一个空扩展名。 Then add your viewhelper under typo3conf/ext/my_ext/Classes/ViewHelpers/
and add this namespace to the top of your template: {namespace my=Tx_MyExt_ViewHelpers}
. 然后在typo3conf/ext/my_ext/Classes/ViewHelpers/
添加typo3conf/ext/my_ext/Classes/ViewHelpers/
,并将此命名空间添加到模板顶部: {namespace my=Tx_MyExt_ViewHelpers}
。 This simple guide may also help you to create the viewhelper itself. 这个简单的指南还可以帮助您创建viewhelper本身。 An advantage is that you can nicely package the viewhelpers and use them in multiple projects. 优点是您可以很好地打包viewhelper并将其用于多个项目中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.