简体   繁体   English

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

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

I have a typo3 fluid template in which I want to check if content exists before rendering some elements. 我有一个typo3流体模板,我想在渲染一些元素之前检查内容是否存在。 Is there an efficient way to do this? 有没有一种有效的方法来做到这一点? eg. 例如。

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

Is there a built-in variable or a simple way to check content exists in a column position? 是否有内置变量或检查内容存在于列位置的简单方法? This is a common task in CMS templating (don't render this part unless there's something to show), but I can't seem to find how to do it simply. 这是CMS模板中的常见任务(除非有显示内容,否则不渲染此部分),但我似乎无法简单地找到如何做到这一点。

There is no easy way to do that. 没有简单的方法可以做到这一点。 But you can use some TypoScript and then pass the count to Fluid and use it in a condition: 但是你可以使用一些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
     }
}

This object will output the number of content rows on the given page and can be accessed in Fluid: 该对象将输出给定页面上的内容行数,可以在Fluid中进行访问:

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

If you're going to use the content anyway and don't have global wrap in your content object, you can also use it directly because the Fluid IfViewHelper checks for empty strings. 如果您要使用内容并且内容对象中没有全局换行,您也可以直接使用它,因为Fluid IfViewHelper会检查空字符串。 So eg this might be working even better: 因此,例如,这可能会更好:

lib.content < styles.content.get

(This object is empty if there is no content) (如果没有内容,则此对象为空)

<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>   

Easyest way to check this with VHS and without TypoScript : 最简单的方法来检查VHS和没有TypoScript

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

You can slide the content throug subpages if you want: 如果需要,您可以通过子页面滑动内容:

<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条件,用于检查分配的变量是否为空。

You can solve this easily: 您可以轻松解决此问题:

  1. In your TypoScript file: 在你的TypoScript文件中:

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

     <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