vierwd/typo3-smarty 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vierwd/typo3-smarty

Composer 安装命令:

composer require vierwd/typo3-smarty

包简介

Use Smarty in Templates instead of Fluid

README 文档

README

Use Smarty in your templates and extbase extensions.

Installation

Install using composer:

composer require 'vierwd/typo3-smarty'

Usage in controllers

To use smarty templates for your extension's actions, just extend the Vierwd\VierwdSmarty\Controller\ActionController. Your templates need to be at the same location as your Fluid templates used to be, but with the file extension .tpl.

Example

// Classes/Controller/BlogController.php
namespace Example\ExampleBlog\Controller;

class BlogController extends \Vierwd\VierwdSmarty\Controller\ActionController {
	/**
	 * @var \Example\ExampleBlog\Domain\Repository\PostRepository
	 * @TYPO3\CMS\Extbase\Annotation\Inject
	 */
	protected $postRepository;

	public function listAction() {
		$posts = $this->postRepository->findAll();
		$this->view->assign('posts', $posts);
	}
}
{* Resources/Private/Templates/Blog/List.tpl *}

{foreach $posts as $post}
	<div class="post">
		<h1>{$post->getTitle()}</h1>

		{$post->getContent()|escape|nl2p nofilter}
	</div>
{/foreach}

Pre-defined variables

There are some variables, that are always available to your templates:

Variable Name Contents
cObj The current ContentObject (instance of TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer)
extensionPath The path to your extension (typo3conf/ext/example_blog/)
extensionName ExampleBlog
pluginName Pi1 (or whatever you defined in ext_tables.php)
controllerName Blog
actionName list
context The controllerContext (instance of TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext)
request The current request (instance of TYPO3\CMS\Extbase\MvcRequest)
typo3Request Psr\Http\Message\ServerRequestInterface
formPrefix Prefix form fields need as name to automatically map form fields to arguments
settings Flexform settings for the plugin
frameworkSettings TypoScript settings for plugin.tx_exampleblog
typolinkService An instance of TYPO3\CMS\Frontend\Service\TypoLinkCodecService
rootLine The rootline for the current page

Pre-defined smarty functions, blocks and modifiers

  • translate
  • uri_resource
  • uri_action
  • link_action
  • flashMessages
  • nl2p
  • email
  • typolink
  • typoscript
  • fluid
  • svg

Power-Blocks: typoscript and fluid

What's realy good about this extension is, that you can still use typoscript and fluid within your Smarty templates. That way you can ensure, that an element gets exactly the same HTML output as a normal content element like Text-with-images. If you write a form, it's also good to fallback to Fluid for some ViewHelpers.

Typoscript

{capture assign=text}
<p>Lorem <b>ipsum</b> dolor sit amet, consectetur adipisicing elit. Dolorem, earum est reiciendis modi neque in veniam rerum deleniti et praesentium? Numquam, odit, itaque voluptate pariatur adipisci enim tempora ducimus dolor!</p>
{/capture}

{typoscript header='TypoScript Example' bodytext=$text CType=text}
lib.parseFunc_RTE >
10 < tt_content
{/typoscript}
Output (Line-breaks added)
<div class="csc-default">
<header class="csc-header"><h1>TypoScript Example</h1></header>
<p>Lorem <b>ipsum</b> dolor sit amet, consectetur adipisicing elit. Dolorem, earum est reiciendis modi neque in veniam rerum deleniti et praesentium? Numquam, odit, itaque voluptate pariatur adipisci enim tempora ducimus dolor!</p>
</div>

The changes to the typoscript will not persist. That way you can remove lib.parseFunc_RTE in one TypoScript Block and still use it in another. It is also possible to use an array data for all arguments:

{capture assign=text}
<p>Lorem <b>ipsum</b> dolor sit amet, consectetur adipisicing elit. Dolorem, earum est reiciendis modi neque in veniam rerum deleniti et praesentium? Numquam, odit, itaque voluptate pariatur adipisci enim tempora ducimus dolor!</p>
{/capture}

{$data=[
	CType => text,
	header => 'TypoScript Example',
	header_layout => 1,
	bodytext => $text
]}

{typoscript data=$data header_layout=2}
lib.parseFunc_RTE >
10 < tt_content
{/typoscript}

Notice, that parameters in the block-tag override array keys (in this example header_layout):

Output (Line-breaks added)
<div class="csc-default">
<header class="csc-header"><h2>TypoScript Example</h2></header>
<p>Lorem <b>ipsum</b> dolor sit amet, consectetur adipisicing elit. Dolorem, earum est reiciendis modi neque in veniam rerum deleniti et praesentium? Numquam, odit, itaque voluptate pariatur adipisci enim tempora ducimus dolor!</p>
</div>

Using Smarty for the base template

It is also possible to use Smarty for the base template of your website in your main TypoScript setup

page = PAGE
page.10 < plugin.tx_vierwdsmarty
page.10.settings {
	template = EXT:example_blog/Resources/Private/Templates/main.tpl

	typoscript.navigation < lib.navigation
	typoscript.footerNavigation < lib.footerNavigation
	typoscript.content < styles.content.get
	typoscript.logo < lib.logo
}

All entries in settings.typoscript will be parsed and will be available as variables in your template.

{* example_blog/Resources/Private/Templates/main.tpl *}
<header>
	{$logo nofilter}
	{$navigation nofilter}
</header>
<div role="main">
	<!--TYPO3SEARCH_begin-->
	{$content nofilter}
	<!--TYPO3SEARCH_end-->
</div>
<footer>{$footerNavigation nofilter}</footer>

Note the nofilter argument for Smarty. By default all variables will be escaped to prevent some XSS attacks.

Using Smarty for Menus

lib.navigation = HMENU
lib.navigation {
	entryLevel = 0

	1 = SMARTY
	1 {
		expAll = 1
		extensionName = vierwd_example
		template = Navigation/Main.tpl

		NO = 1
		ACT = 1
		IFSUB = 1
		ACTIFSUB = 1
	}

	2 < .1
	2.template = Navigation/Submenu.tpl
	3 < .2
}

This code block will load the templates at typo3conf/ext/vierwd_example/Resources/Private/Templates/Navigation/ to render the navigation. Within the template you can iterate over your menu items and output the menu:

<nav class="main-navigation">
	<ul>
	{foreach $menu as $item}
		{$hasSubmenu = $menuObject->isSubMenu($item.uid)}
		{$isActive = $menuObject->isActive($item.uid)}
		<li class="{if $isActive}active{/if}">
			<a href="{$item.uid|typolink}">
				{$item.nav_title|default:$item.title}
			</a>
			{$menuObject->submenu($item.uid) nofilter}
		</li>
	{/foreach}
	</ul>
</nav>

vierwd/typo3-smarty 适用场景与选型建议

vierwd/typo3-smarty 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.61k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 09 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「smarty」 「extension」 「typo3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 vierwd/typo3-smarty 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vierwd/typo3-smarty 我们能提供哪些服务?
定制开发 / 二次开发

基于 vierwd/typo3-smarty 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 5
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 4
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-17