繁体   English   中英

如何检查typo3流体模板中的列内容?

[英]How do I check for column content in a typo3 fluid template?

我有一个typo3流体模板,我想在渲染一些元素之前检查内容是否存在。 有没有一种有效的方法来做到这一点? 例如。

<f:if condition="{contentInColPos0}">
  <div class="section-content">
    <f:render section="Main" />
  </div>
</f:if>

是否有内置变量或检查内容存在于列位置的简单方法? 这是CMS模板中的常见任务(除非有显示内容,否则不渲染此部分),但我似乎无法简单地找到如何做到这一点。

没有简单的方法可以做到这一点。 但是你可以使用一些TypoScript然后将计数传递给Fluid并在以下条件下使用它:

lib.countContent = CONTENT
lib.countContent {
   table = tt_content
   select {
     selectFields = count(uid) AS count
     pidInList = this
     andWhere = (deleted = 0 AND hidden = 0)
   }

   renderObj = COA
   renderObj {
     10 = TEXT
     10 {
       data = field:count
     }
}

该对象将输出给定页面上的内容行数,可以在Fluid中进行访问:

<f:if condition="{f:cObject(typoscriptObjectPath:'lib.countContent')} > 0">
  Then show some stuff
</f:if>

如果您要使用内容并且内容对象中没有全局换行,您也可以直接使用它,因为Fluid IfViewHelper会检查空字符串。 因此,例如,这可能会更好:

lib.content < styles.content.get

(如果没有内容,则此对象为空)

<f:if condition="{f:cObject(typoscriptObjectPath:'lib.content')}">
  <f:then>
    <f:format.html>{lib.content}</f:format.html>
  </f:then>
  <f:else>
    No content found
  </f:else>
</f:if>   

最简单的方法来检查VHS和没有TypoScript

<f:if condition="{v:content.get(column:6) -> v:iterator.first()}">
    <div class="myAmazingClass">
    </div>
</f:if>

如果需要,您可以通过子页面滑动内容:

<f:if condition="{v:content.get(column:6, slide:'-1') -> v:iterator.first()}">
    <div class="myAmazingClass">
    </div>
</f:if>

考虑将VHS与ViewHelpers https://fluidtypo3.org/viewhelpers/vhs/master/Content/GetViewHelper.htmlhttps://fluidtypo3.org/viewhelpers/vhs/master/Content/RenderViewHelper.html结合使用,并使用as参数和一个f:if条件,用于检查分配的变量是否为空。

您可以轻松解决此问题:

  1. 在你的TypoScript文件中:

     lib.contentInColPos0 < styles.content.get lib.contentInColPos0 t.select.where = colPos = 0 
  2. 在您的模板文件中:

     <f:if condition="{f:cObject(typoscriptObjectPath:'lib.contentInColPos0')}"> <div class="section-content"> <f:render section="Main" /> </div> </f:if> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM