为什么 TYPO3 9.5.x Fluid Viewhelper f:security 仅在 Default.html 中有效,而在 List.html 中无效?
Why TYPO3 9.5.x Fluid Viewhelper f:security only works in Default.html but not in List.html?
在 TYPO3 9.5.x 中,此代码适用于我的 extbase 扩展的 Layout/Default.html 模板。但是相同的代码不适用于任何其他模板,例如 List.html 模板。当我在那里使用它时,我没有得到 viewhelper 的 any 输出。在 TYPO3 8.x 中,它适用于每个模板,而不仅仅是 Default.html。有充分的理由吗?我如何在非 Layout/Default.html?
的部分和模板中使用 f:security
<f:security.ifHasRole role="2">
<f:then>
<p>CHECK RIGHTS role=2</p>
</f:then>
<f:else>
<p>CHECK RIGHTS role=not2</p>
</f:else>
</f:security.ifHasRole>
与此代码相同,因此与 f:else:
无关
<f:security.ifAuthenticated>
<p>I AM LOGGED IN, but it does not show up :( </p>
</f:security.ifAuthenticated>
Layout/Default.html:
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:security.ifHasRole role="2">
<p>ROLE is 2 in Default.html, this gets rendered as expected</p>
</f:security.ifHasRole>
<div class="container">
<f:debug title="Debug" maxDepth="12">{_all}</f:debug>
<f:render section="content" />
</div><!-- /container -->
</html>
Templates/Statistic/List.html
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default" />
This Template is responsible for creating a table of domain objects.
If you modify this template, do not forget to change the overwrite settings
in /Configuration/ExtensionBuilder/settings.yaml:
Resources:
Private:
Templates:
List.html: keep
Otherwise your changes will be overwritten the next time you save the extension in the extension builder
<f:section name="content">
<h3>Anruf-Statistiken</h3>
<f:flashMessages />
<div style="float:right; clear:both;"><f:link.action action="export" controller="Statistic" pluginName="Run"><button type="button" class="btn btn-xs btn-default">Tabelle für Excel speichern (CSV-Export)</button></f:link.action></div>
<table style="padding: 1em; margin-top:2em; width:100%;" class="tx_srv2" >
<tr>
<th style="padding: 1em;">ID</th>
<th style="padding: 1em;">Timestamp</th>
<th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.agent" /></th>
<th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.status" /></th>
<th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.campaigntitle" /></th>
<th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.duration" /> (sec.)</th>
<th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.comment" /></th>
</tr>
<f:widget.paginate objects="{statistics}" configuration="{itemsPerPage: 10, insertBelow:1}" as="paginatedStatistics">
<f:for each="{paginatedStatistics}" as="statistic">
<tr>
<td style="padding: 1em;">{statistic.uid}</td>
<td style="padding: 1em;"><f:format.date format="Y-m-d H:i:s">{statistic.crdate}</f:format.date></td>
<td style="padding: 1em;">{statistic.agent.username}</td>
<td style="padding: 1em;">{statistic.status}</td>
<td style="padding: 1em;">{statistic.campaigntitle}</td>
<td style="padding: 1em;">{statistic.duration}</td>
<td style="padding: 1em;">{statistic.comment}</td>
</tr>
</f:for>
</f:widget.paginate>
</table>
<f:security.ifAuthenticated>
<f:then>
This part should be shown if there is a frontend user logged in, but it never shows up.
</f:then>
<f:else>
This part should be shown if the current user is not logged in., but it also doesnt show up.
</f:else>
</f:security.ifAuthenticated>
</f:section>
</html>
在前端,List.html 中的 f:security 部分没有内容被渲染,但是 Default.html 中的 f:security 部分被渲染。 List.html 的通常输出,即对象列表,按预期呈现。
用法看起来非常好。
f:security
ViewHelpers 只能在前端工作。如果您在后端范围内,则需要使用 f:be.security
等效项。
如果这样还不能解决问题,能否请您提供故障ViewHelper使用的模板代码?
在 TYPO3 9.5.x 中,ViewHelper 似乎只是 returns 一个布尔值,不会呈现 "then" 或 "else" 标签。这对我有用:
<f:if condition="{f:security.ifHasRole( role: '9')}">
<f:then>
yes
</f:then>
<f:else>
no
</f:else>
</f:if>
在 9.5.2 中遇到了这个问题并且检查角色不是一个选项,这是我在 vhs 扩展的帮助下解决它的方法:
<f:security.ifAuthenticated>
<f:then>
<v:variable.set name="isLoggedIn" value="true"/>
</f:then>
</f:security.ifAuthenticated>
<f:if condition="{isLoggedIn}">
<f:then>### Logged In ###</f:then>
<f:else>### Not Logged In ###</f:else>
</f:if>
这里的技巧是 Viewhelper 能够执行 f:then
块中的操作,但不能执行 f:else
块中的操作,因此我创建了一个仅在f:then
块,稍后检查此变量。
在 TYPO3 9.5.x 中,此代码适用于我的 extbase 扩展的 Layout/Default.html 模板。但是相同的代码不适用于任何其他模板,例如 List.html 模板。当我在那里使用它时,我没有得到 viewhelper 的 any 输出。在 TYPO3 8.x 中,它适用于每个模板,而不仅仅是 Default.html。有充分的理由吗?我如何在非 Layout/Default.html?
的部分和模板中使用 f:security<f:security.ifHasRole role="2">
<f:then>
<p>CHECK RIGHTS role=2</p>
</f:then>
<f:else>
<p>CHECK RIGHTS role=not2</p>
</f:else>
</f:security.ifHasRole>
与此代码相同,因此与 f:else:
无关<f:security.ifAuthenticated>
<p>I AM LOGGED IN, but it does not show up :( </p>
</f:security.ifAuthenticated>
Layout/Default.html:
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:security.ifHasRole role="2">
<p>ROLE is 2 in Default.html, this gets rendered as expected</p>
</f:security.ifHasRole>
<div class="container">
<f:debug title="Debug" maxDepth="12">{_all}</f:debug>
<f:render section="content" />
</div><!-- /container -->
</html>
Templates/Statistic/List.html
<html xmlns:f="https://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">
<f:layout name="Default" />
This Template is responsible for creating a table of domain objects.
If you modify this template, do not forget to change the overwrite settings
in /Configuration/ExtensionBuilder/settings.yaml:
Resources:
Private:
Templates:
List.html: keep
Otherwise your changes will be overwritten the next time you save the extension in the extension builder
<f:section name="content">
<h3>Anruf-Statistiken</h3>
<f:flashMessages />
<div style="float:right; clear:both;"><f:link.action action="export" controller="Statistic" pluginName="Run"><button type="button" class="btn btn-xs btn-default">Tabelle für Excel speichern (CSV-Export)</button></f:link.action></div>
<table style="padding: 1em; margin-top:2em; width:100%;" class="tx_srv2" >
<tr>
<th style="padding: 1em;">ID</th>
<th style="padding: 1em;">Timestamp</th>
<th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.agent" /></th>
<th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.status" /></th>
<th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.campaigntitle" /></th>
<th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.duration" /> (sec.)</th>
<th style="padding: 1em;"><f:translate key="tx_srv2_domain_model_statistic.comment" /></th>
</tr>
<f:widget.paginate objects="{statistics}" configuration="{itemsPerPage: 10, insertBelow:1}" as="paginatedStatistics">
<f:for each="{paginatedStatistics}" as="statistic">
<tr>
<td style="padding: 1em;">{statistic.uid}</td>
<td style="padding: 1em;"><f:format.date format="Y-m-d H:i:s">{statistic.crdate}</f:format.date></td>
<td style="padding: 1em;">{statistic.agent.username}</td>
<td style="padding: 1em;">{statistic.status}</td>
<td style="padding: 1em;">{statistic.campaigntitle}</td>
<td style="padding: 1em;">{statistic.duration}</td>
<td style="padding: 1em;">{statistic.comment}</td>
</tr>
</f:for>
</f:widget.paginate>
</table>
<f:security.ifAuthenticated>
<f:then>
This part should be shown if there is a frontend user logged in, but it never shows up.
</f:then>
<f:else>
This part should be shown if the current user is not logged in., but it also doesnt show up.
</f:else>
</f:security.ifAuthenticated>
</f:section>
</html>
在前端,List.html 中的 f:security 部分没有内容被渲染,但是 Default.html 中的 f:security 部分被渲染。 List.html 的通常输出,即对象列表,按预期呈现。
用法看起来非常好。
f:security
ViewHelpers 只能在前端工作。如果您在后端范围内,则需要使用 f:be.security
等效项。
如果这样还不能解决问题,能否请您提供故障ViewHelper使用的模板代码?
在 TYPO3 9.5.x 中,ViewHelper 似乎只是 returns 一个布尔值,不会呈现 "then" 或 "else" 标签。这对我有用:
<f:if condition="{f:security.ifHasRole( role: '9')}">
<f:then>
yes
</f:then>
<f:else>
no
</f:else>
</f:if>
在 9.5.2 中遇到了这个问题并且检查角色不是一个选项,这是我在 vhs 扩展的帮助下解决它的方法:
<f:security.ifAuthenticated>
<f:then>
<v:variable.set name="isLoggedIn" value="true"/>
</f:then>
</f:security.ifAuthenticated>
<f:if condition="{isLoggedIn}">
<f:then>### Logged In ###</f:then>
<f:else>### Not Logged In ###</f:else>
</f:if>
这里的技巧是 Viewhelper 能够执行 f:then
块中的操作,但不能执行 f:else
块中的操作,因此我创建了一个仅在f:then
块,稍后检查此变量。