BE上下文中的独立视图 [英] Fluid standalone view in BE context

查看:91
本文介绍了BE上下文中的独立视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于您处于BE或CLI上下文中(例如,通过extbase命令控制器任务发送电子邮件),以下代码最多可以处理7个LTS,以呈现流畅的独立视图:

Given you are in a BE or CLI context (e.g. sending emails via extbase command controller task), the following worked up to 7 LTS for rendering a fluid standalone view:

$view = $this->objectManager->get(StandaloneView::class);
$view->setTemplatePathAndFilename('/Absolute/Path/To/Template.html');
$view->setFormat('html');
$view->getRequest()->setControllerExtensionName('Myextensionname');
return trim($view->render());

但是,在8个LTS中,这会引发以下异常:

However, in 8 LTS, this throws the following exception:

尝试为控制器动作"Standard-> index"解析格式为".html"的模板文件,但路径均未包含预期的模板文件……未配置路径.

Tried resolving a template file for controller action "Standard->index" in format ".html", but none of the paths contained the expected template file… No paths configured.

如Wiki页面上的建议,网址为 https://wiki.typo3.org/How_to_use_the_use_the_use_templateUsage_in_TYPO3_8.7 ,我尝试设置视图的布局和部分根路径:

As suggested in the wiki page at https://wiki.typo3.org/How_to_use_the_Fluid_Standalone_view_to_render_template_based_emails#Usage_in_TYPO3_8.7, I tried setting layout and partial root paths for the view:

$view->setLayoutRootPaths(['EXT:Myextensionname/Resources/Private/Layouts/']);
$view->setPartialRootPaths(['EXT:Myextensionname/Resources/Private/Partials/']);

但是,这无法解决问题.

However, this won't do the trick.

深入研究,我可以想象必须设置控制器和动作名称,例如通过设置控制器上下文,但这似乎不是一个可靠的解决方案,因为有多个其他类实例与之绑定.

Digging a bit deeper, I could imagine that one would have to set the controller and action name, e.g. by setting the controller context, but that does not seem to be a solid solution as multiple other class instances are tied to it.

在8个LTS中呈现流畅的独立视图的正确方法是什么?

What is the correct way to render fluid standalone views in 8 LTS?

推荐答案

StandaloneView喜欢接收所有模板路径(部分,模板和布局根路径),因此,如果您尚未提供所有路径,则应该这样做.原因是命名为独立"是指视图既不绑定到特定的MVC操作也不绑定到特定的扩展上下文.

StandaloneView likes to receive all template paths (partial, template and layout root paths) so if you don't already provide all of them, you should do so. The reason being that the naming "Standalone" refers to the view being tied neither to a specific MVC action nor a specific extension context.

也就是说,如果您使用8.7.5,则很有可能被 https://review.typo3.org/#/c/53917/,因此在进行大型重构之前可能值得一试.从技术上讲,StandaloneView 可以像具有扩展上下文的TemplateView一样进行操作,这只是不受官方支持的行为,并且TYPO3可能无法始终如一地应用您期望的所有上下文.

That said, if you use 8.7.5 there's a chance you are hit by a regression that is going to be solved by https://review.typo3.org/#/c/53917/ so it might be worth checking that out before you do a major refactoring. Technically the StandaloneView can be operated like a TemplateView with extension context, it's just not officially supported behavior and TYPO3 may not consistently apply all of the context you expect.

这篇关于BE上下文中的独立视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆