简体   繁体   English

Typo3-内容选择:渲染重复项

[英]Typo3 - CONTENT Select: Render dupplicats

I try to list all File-Records depending on the given categories. 我尝试根据给定的类别列出所有文件记录。 So I had problems to list all Files with the right categories and asked about it here (solved) . 因此,我在列出所有具有正确类别的文件时遇到了问题,并在此处询问(已解决)

Now I got to the problem described here . 现在我解决了这里描述的问题。

In short: Typo3 saves already rendered records and dosen't render it again to prevent endless loops. 简而言之:Typo3保存已渲染的记录,并且不再渲染以防止循环不断。 But I need to get the records rendered. 但我需要获取记录。

My Typo3 version is 7.6.18. 我的Typo3版本是7.6.18。

I started with this working code, which just displays all Files wich have a relation with the categorie uid=1 and his childs (described further in my previous question-thread): 我从此工作代码开始,该代码仅显示所有与uiduid = 1和他的孩子有关联的文件(在我先前的问题线程中有进一步描述):

lib.documentindex = CONTENT
lib.documentindex {
  wrap = <ul>|</ul>

  table = sys_category
  select {
    pidInList = 1
    recursive = 1000
    selectFields = sys_file.name, sys_file.identifier, sys_category.title
    join = sys_category_record_mm ON (sys_category_record_mm.uid_local = sys_category.uid) JOIN sys_file_metadata ON (sys_file_metadata.uid = sys_category_record_mm.uid_foreign) JOIN sys_file ON (sys_file_metadata.file = sys_file.uid)
    where = (sys_category_record_mm.tablenames = "sys_file_metadata") AND (sys_category_record_mm.fieldname = "categories") AND ((sys_category.parent = 1) OR (sys_category.uid = 1))
    orderBy = sys_category.title
  }

  renderObj = COA
  renderObj.wrap = <li>|</li>
  renderObj.10 = TEXT
  renderObj.10 {
    field = identifier
    wrap = <a href="|">
  }
  renderObj.20 = TEXT
  renderObj.20.field = name
  renderObj.30 = TEXT
  renderObj.30.value = </a>

}

But now, I want to display this more grouped on categories, like: 但是现在,我想按类别显示更多的分组信息,例如:

Name Of Cat 1
 - File 1
 - File 2
Name Of Cat 2
- File 3

For this I have advanced the code like this: 为此,我改进了如下代码:

lib.documentindex = CONTENT
lib.documentindex {
  wrap = <ul>|</ul>

  table = sys_category
  select {
    pidInList = 1
    recursive = 1000
    selectFields = sys_category.title, sys_category.uid as theuid
    join = sys_category_record_mm ON (sys_category_record_mm.uid_local = sys_category.uid) JOIN sys_file_metadata ON (sys_file_metadata.uid = sys_category_record_mm.uid_foreign) JOIN sys_file ON (sys_file_metadata.file = sys_file.uid)
    where = (sys_category_record_mm.tablenames = "sys_file_metadata") AND (sys_category_record_mm.fieldname = "categories") AND ((sys_category.parent = 1) OR (sys_category.uid = 1))
    orderBy = sys_category.title
    groupBy = sys_category.title
  }

  renderObj = COA
  renderObj.wrap = <li>|</li>
  renderObj.10 = TEXT
  renderObj.10 {
    field = title
    wrap = <h3>|</h3>
  }

  renderObj.20 = CONTENT
  renderObj.20 {

    table = sys_category
    select {
      begin = 0
      pidInList = 1
      recursive = 1000
      selectFields = sys_file.name, sys_file.identifier
      join = sys_category_record_mm ON (sys_category_record_mm.uid_local = sys_category.uid) JOIN sys_file_metadata ON (sys_file_metadata.uid = sys_category_record_mm.uid_foreign) JOIN sys_file ON (sys_file_metadata.file = sys_file.uid)
      where = (sys_category_record_mm.tablenames = "sys_file_metadata") AND (sys_category_record_mm.fieldname = "categories")
      orderBy = sys_file.name
      andWhere.cObject = TEXT
      andWhere.cObject.dataWrap = sys_category.uid='{field:theuid}'
      //andWhere.cObject.dataWrap = sys_category.uid='4'
      andWhere.cObject.insertData= 1

    }

    renderObj = COA
    renderObj.wrap = <li>|</li>
    renderObj.10 = TEXT
    renderObj.10 {
      field = identifier
      wrap = <a href="|">
    }
    renderObj.20 = TEXT
    renderObj.20.field = name
    renderObj.30 = TEXT
    renderObj.30.value = </a>

  }

}

The first query is for displaying the titles of categories which have at least 1 file connected with, and the 2nd select is for displaying the files which are connected. 第一个查询用于显示与至少一个文件相关联的类别的标题,第二个选择用于显示与文件相关联的类别。

The problem is now, that the files are saved because of the first select and are so locked from being rendered in the 2nd query. 现在的问题是,由于第一次选择,文件被保存,因此被锁定,无法在第二个查询中呈现。

I could not find a typoscript-only workaround, but I have seen that this problem is known for a long time. 我找不到仅排印的解决方法,但是我已经知道这个问题已经存在很长时间了。 Now my question: Does somebody know a workaround for the problem, with only typoscript? 现在我的问题是:有人知道只有打字错误才能解决该问题吗? I don't want a solution which is split over multiple files, because I'm new on typo3 and I don't have an overview over our typo3-projects already. 我不需要拆分为多个文件的解决方案,因为我是typo3的新手,而且我还没有关于typo3-项目的概述。

Edit 1: 编辑1:

So I changed the order of the 2nd query as Bernd Wilke πφ has told me to: 因此,我更改了第二个查询的顺序,因为Bernd Wilkeπφ告诉我:

renderObj.20 {

    table = sys_file
    select {
      begin = 0
      pidInList = 1
      recursive = 1000
      selectFields = sys_file.name, sys_file.identifier
      join = sys_file_metadata ON (sys_file_metadata.file = sys_file.uid) JOIN sys_category_record_mm ON (sys_file_metadata.uid = sys_category_record_mm.uid_foreign)
      where = (sys_category_record_mm.tablenames = "sys_file_metadata") AND (sys_category_record_mm.fieldname = "categories")
      orderBy = sys_file.name
      andWhere.cObject = TEXT
      andWhere.cObject.dataWrap = sys_category_record_mm.uid_local='{field:theuid}'
      andWhere.cObject.dataWrap = //sys_category_record_mm.uid_local='2' OR sys_category_record_mm.uid_local='4'
      andWhere.cObject.insertData= 1
    }

    renderObj = COA
    renderObj.wrap = <li>|</li>
    renderObj.10 = TEXT
    renderObj.10 {
      field = identifier
      wrap = <a href="|">
    }
    renderObj.20 = TEXT
    renderObj.20.field = name
    renderObj.30 = TEXT
    renderObj.30.value = </a>

  }

AS far as I can tell now, this replaces the problem of not rendering the records I need with the problem it don't render a thing I need at all. 就我现在所知,这代替了不呈现我所需记录的问题,而根本不呈现我所需要的东西。

Do I replace 我要更换吗

sys_category_record_mm.uid_local='{field:theuid}'
//andWhere.cObject.dataWrap = sys_category_record_mm.uid_local='2' OR sys_category_record_mm.uid_local='4'

with

//sys_category_record_mm.uid_local='{field:theuid}'
  andWhere.cObject.dataWrap = sys_category_record_mm.uid_local='2' OR sys_category_record_mm.uid_local='4'

Some records are shown, but I've again the strange problem that only the condition after 'OR' counts. 显示了一些记录,但是我又遇到了一个奇怪的问题,只有“ OR”之后的条件才算在内。 So only records with the category.uid=4 are displayed. 因此,仅显示category.uid = 4的记录。 If I change it to 2 in the code, it displays the records with category.uid=2. 如果在代码中将其更改为2,它将显示category.uid = 2的记录。 Anyway, if it's a bug or something else, I don't care for now. 无论如何,如果是错误或其他问题,我现在不在乎。 Because I want it to work with andWhere.cObject.dataWrap = sys_category_record_mm.uid_local='{field:theuid}' and it does not. 因为我希望它与andWhere.cObject.dataWrap = sys_category_record_mm.uid_local='{field:theuid}' ,但它没有。

Edit2: 编辑2:

Ok I got it to work as expected, but the way I did it, is so strange, that I don't want to use it. 好的,我可以按预期工作,但是我做的方式却很奇怪,以至于我不想使用它。

Solution: 解:

renderObj.20 {

    table = sys_file
    select {
      begin = 0
      pidInList = 1
      recursive = 1000
      selectFields = sys_file.name, sys_file.identifier
      join = sys_file_metadata ON (sys_file_metadata.file = sys_file.uid) JOIN sys_category_record_mm ON (sys_file_metadata.uid = sys_category_record_mm.uid_foreign)
      where = (sys_category_record_mm.tablenames = "sys_file_metadata") AND (sys_category_record_mm.fieldname = "categories")
      orderBy = sys_file.name
      andWhere.cObject = TEXT
      andWhere.cObject.dataWrap = 0 OR sys_category_record_mm.uid_local='{field:theuid}'
      //andWhere.cObject.dataWrap = sys_category_record_mm.uid_local='2' OR sys_category_record_mm.uid_local='4'
      andWhere.cObject.insertData= 1
    }

So, I learned: In Typo3 conditions only matter if an OR-operator is standing before the condition. 因此,我了解到:在Typo3条件下,仅当OR运算符站在条件之前时才重要。 Well, just a Typo3-thing? 好吧,只是错别字?

andWhere should not be starting with the field name but with AND, OR or another official SQL statement. andWhere不应以字段名称开头,而应以AND,OR或其他正式SQL语句开头。 So you should replace the line 所以你应该更换线

andWhere.cObject.dataWrap = 0 OR sys_category_record_mm.uid_local='{field:theuid}'

with

andWhere.cObject.dataWrap = AND sys_category_record_mm.uid_local='{field:theuid}'

Maybe this feels less weird then. 也许那时感觉不那么奇怪了。 ;-) ;-)

So here we go with the fully edited solution: 因此,这里我们使用经过完全编辑的解决方案:

lib.documentindex = CONTENT
lib.documentindex {
  wrap = <ul>|</ul>    
  table = sys_category
  select {
    pidInList = 1
    recursive = 1000
    selectFields = sys_category.title, sys_category.uid as theuid
    join (
          sys_category_record_mm 
          ON (sys_category_record_mm.uid_local = sys_category.uid)
    JOIN sys_file_metadata 
          ON (sys_file_metadata.uid = sys_category_record_mm.uid_foreign)
    )
    where (
      (sys_category_record_mm.tablenames = "sys_file_metadata") AND 
      (sys_category_record_mm.fieldname = "categories") AND 
      ((sys_category.parent = 1) OR (sys_category.uid = 1))
    )
    orderBy = sys_category.title
    groupBy = sys_category.title
  }

  // context = sys_category
  renderObj = COA
  renderObj {
    wrap = <li>|</li>
    10 = TEXT
    10 {
      dataWrap = <h3>{field:title}</h3>
    }

    20 = CONTENT
    20 {
      table = sys_file
      select {
        pidInList = 1
        recursive = 1000
        selectFields = sys_file.name, sys_file.identifier
        join (
               sys_file_metadata 
                 ON (sys_file_metadata.file = sys_file.uid) 
          JOIN sys_category_record_mm 
                 ON (sys_file_metadata.uid = sys_category_record_mm.uid_foreign)
        )
        where (
          (sys_category_record_mm.tablenames = "sys_file_metadata") AND
          (sys_category_record_mm.fieldname = "categories")
        )
        orderBy = sys_file.name
        andWhere.dataWrap = AND sys_category_record_mm.uid_local='{field:theuid}'
        }
      }

      // context: sys_file
      renderObj = TEXT
      renderObj {
        wrap = <li>|</li>
        field = name
        typolink.parameter.field = identifier
      }
    }
  }
}

OK, it don't make sense, but it's solved. 好的,这没有意义,但是已经解决了。 I would like to know why it works like this. 我想知道为什么会这样。 But I may should stop asking myself about typo3. 但是我应该停止问自己有关typo3的问题。

Solution: 解:

In Typo3 conditions only matter if an OR-operator is standing before it?! 在Typo3中,条件是否重要,如果OR运算符在其前面?

lib.documentindex = CONTENT
lib.documentindex {
  wrap = <ul>|</ul>

  table = sys_category
  select {
    pidInList = 1
    recursive = 1000
    selectFields = sys_category.title, sys_category.uid as theuid
    join (
          sys_category_record_mm 
          ON (sys_category_record_mm.uid_local = sys_category.uid)
    JOIN sys_file_metadata 
          ON (sys_file_metadata.uid = sys_category_record_mm.uid_foreign)
    )
    where (
      (sys_category_record_mm.tablenames = "sys_file_metadata") AND 
      (sys_category_record_mm.fieldname = "categories") AND 
      ((sys_category.parent = 1) OR (sys_category.uid = 1))
    )
    orderBy = sys_category.title
    groupBy = sys_category.title
  }

  // context = sys_category
  renderObj = COA
  renderObj {
    wrap = <li>|</li>
    10 = TEXT
    10 {
      field = title
      wrap = <h3>|</h3>
    }

    20 = CONTENT
    20 {
      table = sys_file
      select {
        begin = 0
        pidInList = 1
        recursive = 1000
        selectFields = sys_file.name, sys_file.identifier
        join (
               sys_file_metadata 
                 ON (sys_file_metadata.file = sys_file.uid) 
          JOIN sys_category_record_mm 
                 ON (sys_file_metadata.uid = sys_category_record_mm.uid_foreign)
        )
        where (
          (sys_category_record_mm.tablenames = "sys_file_metadata") AND
          (sys_category_record_mm.fieldname = "categories")
        )
        orderBy = sys_file.name
        andWhere.cObject = TEXT
        andWhere.cObject {
          dataWrap = 0 OR sys_category_record_mm.uid_local='{field:theuid}'
          insertData= 1
        }
      }

      // context: sys_file
      renderObj = TEXT
      renderObj {
        wrap = <li>|</li>
        field = name
        typolink.parameter.field = identifier
      }
    }
  }
}

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

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