Pass content from TypoScript to fluid template in

2019-07-18 08:48发布

问题:

I would like to read content via TypoScript and render it through a custom Fluid template. Without css_styled_content or fluid_styled_content.

temp.test = CONTENT
temp.test {
  table = tt_content
  select.languageField = 1
  select.selectFields = bodytext,image,header,header_link
  select.where = colPos = 1
  renderObj = FLUIDTEMPLATE
  renderObj {
    file = path/to/Teaser.html
  }
}

This works with strings, say

<f:debug>{data.header}</f:debug>

But not with

<f:debug>{data.image}</f:debug>

returning only the number of images.

Now, in a classic TypoScript RenderObj (maybe a COA), you would have added something like

10 = FILES
10 {
  required = 1
  references {
    table = tt_content
    fieldName = image
  }
  renderObj = IMAGE
  renderObj {
    file.import.data = file:current:originalUid // file:current:uid
    file.width=654
    file.height = 327c
    //stdWrap.typolink.parameter.data = file:current:link
    altText.data = file:current:description // file:current:title // file:current:alternative
  }
}

While nowadays, we want to do that in the Fluid template. But how to resolve the FAL image to pass it to the fluid template?

回答1:

You should be able to use the TYPO3\CMS\Frontend\DataProcessing\FilesProcessor data processor that will fetch the file data for you so you can access it with {files} in your template.

renderObj = FLUIDTEMPLATE
renderObj {
  file = path/to/Teaser.html
  dataProcessing {
    10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
    10.references.fieldName = image
  }
}


回答2:

The main problem is all image information are stored in a different table called "sys_file_reference". Selecting "tt_content.image" will not help you here. There are 2 ways to solve this problem, IMHO.

1) Create your own viewhelper. This VH can be utilized to query the images as it is done here.

2) Create a small TypoScript lib and use it as f:cObject in your fluid template. This is described here.

I'm not saying that my solution is the best one. But it's the only one I'm aware of. Looking forward seeing better solutions ;)