1
votes

I'm currently building an extension with TYPO3, which does extend the pages table of the TYPO3 core by another field.

Description of my problem:

The field is a MM relation to my own record, containing a description, some images and so on... Because my extension doesn't provide its own plugin (it's an general site extension, providing the sites templates and so on) I have to access the new fields of the pages record via fluid template. But, by accessing this field within the pages info array (with <v:page.info field="myfield" ... /> or {data.myfield}), I only get the current count of referenced rows (the value of the database column in the pages-record).

So, my questions are:

  • How can I access the contents of that additional field in my fluid template, forcing TYPO3 to recognize this jump over the MM table to my referenced records? Whats the usual "TYPO3-way" for that?

  • Or do I have to write my own ViewHelper just for getting references between two records?

  • Are there any TypoScript solutions for this?

What my TCA (extended pages) looks like:

$temporaryColumns = array(
    'tx_user_myext_myfield' => array(
        /* ... some smaller unimportant TCA settings here ... */
        'config' => array(
            'type' => 'group',
            'internal_type' => 'db',
            'allowed' => 'tx_user_myext_mycustomrow',
            'foreign_table' => 'tx_user_myext_mycustomrow',
            'MM' => 'tx_user_myext_mycustomrow_pages_MM',
            'MM_hasUidField' => 1,
            'multiple' => 1
        )
    )
);

(Of course, I pass $temporaryColumns to addTCAcolumns and addToAllTCAtypes. The backend functionality works fine - that's not the problem.)

EDIT: I can't build a plugin for that, because it's a general part of the website. (So, it will be settled in the template.) Only the record relations should be changeable by the user.

I hope you can help me; thank you very much for any reply to this question.

3
How do you get the data variable in {data.myfield}? Is it loaded with some extension or are you using plain TypoScript?Dimitri L.
@DimitriL. No, as I know, {data} is part of the default variables of a fluid template, containing data of the current page record. Am I wrong with this guess?Tim Wißmann
There are no default variables in a fluid template if you are not using it inside a plugin, as far as I know, but may be there were some changes i missed. What does <f:debug>{data}</f:debug> say?Dimitri L.
@DimitriL. Thanks for your reply. First of all, debugging {_all} says, that there are two variables available in my template: data (an array) and current (which is NULL). {data} contains all database columns of the page record and its values. (e.g. uid, pid, t3ver_*, ..., author, ..., nav_title, nav_hide, content_from_pid, ... and last but not least: tx_user_myext_myfield). As already mentioned above, tx_user_myext_myfield does only contain the count of referenced items.Tim Wißmann

3 Answers

3
votes

The best way would be to extend/create the Page Model and create a plugin for showing your stuff.

It is also possible to do it with TypoScript

myRecords = CONTENT
myRecords {
  table = tx_user_myext_mycustomrow
  select {
    pidInList = root,-1
    selectFields = tx_user_myext_mycustomrow.*
    join = tx_user_myext_mycustomrow_pages_MM ON tx_user_myext_mycustomrow_pages_MM.uid_local = tx_user_myext_mycustomrow.uid
    where.data = field:_ORIG_uid // field:uid
    where.intval = 1
    where.wrap = tx_user_myext_mycustomrow_pages_MM.uid_foreign=|
    orderBy = tx_user_myext_mycustomrow_pages_MM.sorting_foreign
  }
  renderObj = COA
  renderObj.10 = TEXT
  renderObj.10.field = somefield
  renderObj.10.wrap = <h1>|</h1>
}

# add myRecords to your fluid variables. I assume that the fluidtemplate is in page.10

page.10.variables.myRecords < myRecords

In Fluid:

<f:render.raw>{myRecords}</f:render.raw>

As you see the TS solution has almost no relation to Fluid since the html is build in TS. I would advice going the way with an own plugin. It takes not much time to add the relation field to the page model and create a small plugin and is a good training for further development.

1
votes

Using the DatabaseQueryProcessor (as @bschauer says) it's possible to use a partial to separate your HTML from Typoscript.

TypoScript configuration:

page.10.variables.myRecords = CONTENT
page.10.variables.myRecords {
    table = tx_user_myext_mycustomrow
    select {
        pidInList = root,-1
        selectFields = tx_user_myext_mycustomrow.*
        join = tx_user_myext_mycustomrow_pages_MM ON tx_user_myext_mycustomrow_pages_MM.uid_local = tx_user_myext_mycustomrow.uid
        where.data = field:uid
        where.intval = 1
        where.wrap = tx_user_myext_mycustomrow_pages_MM.uid_foreign=|
        orderBy = tx_user_myext_mycustomrow_pages_MM.sorting_foreign
    }
    renderObj = FLUIDTEMPLATE
    renderObj {
      file = EXT:tx_user_myext/Resources/Private/Partials/MyTemplate.html
      dataProcessing {
        10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
        10.references.fieldName = tx_user_myext_myfield
      }
    }
  }
}

Partial MyTemplate.html:

h1>{data.somefield}</h1>

In your Fluid template:

<f:format.raw>{myRecords}</f:format.raw>
0
votes

Couldn't you use the DatabaseQueryProcessorfor that?

Example TypoScript configuration:

  10 = TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
  10 {
    table = tt_address
    pidInList = 123
    where = company="Acme" AND first_name="Ralph"
    order = RAND()
    as = addresses
    dataProcessing {
      10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
      10 {
        references.fieldName = image
      }
    }
  }

https://github.com/TYPO3/TYPO3.CMS/blob/master/typo3/sysext/frontend/Classes/DataProcessing/DatabaseQueryProcessor.php