Paolito75
Paolito75

Reputation: 568

TYPO3/Typoscript : render sql query as array

I am using TYPO3 6.2. On my website, i make a SQL query this way :

lib.bloc_top = COA
lib.bloc_top.10 < styles.content.get
lib.bloc_top.10.select.selectFields = header
lib.bloc_top.10.select.where = ( deleted = 0 && hidden = 0 && tx_gridelements_container = 2571 && CType = 'header' )

All works but instead of outputting the results as HTML code, I would like to render it in an array that I would use in my FLUID template this way :

<f:for each="{car}" as="el">
    <li>Brand : {el}</li>
  </f:for>

Is it possible ? Thanks for your help :)

Upvotes: 0

Views: 687

Answers (1)

Jo Hasenau
Jo Hasenau

Reputation: 2684

You should not select the container by a specific UID, but create a "car" container type via Gridelements CE backend layout instead.

Anyway, to get the data into an array, you don't have to do anything special, since this is automatically done by styles.content.get under the hood.

While styles.content.get uses the default tt_content setup, you can change that via renderObj as described here: https://docs.typo3.org/typo3cms/TyposcriptReference/6.2/ContentObjects/Content/

To get the data into your Fluid template you just have to replace the default renderObj with a FLUIDTEMPLATE https://docs.typo3.org/typo3cms/TyposcriptReference/6.2/ContentObjects/Fluidtemplate/Index.html

lib.bloc_top.10.renderObj = FLUIDTEMPLATE
lib.bloc_top.10.renderObj {
  file = path/to/your/template/file.html
}

Since the loop is handled by the CONTENT object of styles.content.get, you can skip the f:for part in your template though.

Usually any kind of data is provided within the cObj->data array, so something like <h1>{data.header}</h1> should do the job.

And even with CONTENT there should be a counter, since there is https://docs.typo3.org/typo3cms/TyposcriptReference/DataTypes/Gettext/Index.html#cobj

To get any available data you should use <f:debug>{_all}</f:debug> in your Fluid template.

Upvotes: 1

Related Questions