Tillebeck
Tillebeck

Reputation: 3523

TYPO3: Special tt_contenttype. Modify content before output

Can I create a "special" type of tt_content, so text is beeing processed in some custom ways before outputtet?

In my case I would like to add ###MY_MARKER### somewhere in header and/or bodytext and have it replaced by the right words for the given page.

eg:

I CAN do it by making a custom plugin. Question is more if I can reuse normal tt_contant for the same purpose

Upvotes: 0

Views: 731

Answers (1)

tmt
tmt

Reputation: 8654

Yes, you can easily extend the tt_content by adding your own TCA configuration to the typo3conf/extTables.php file:

t3lib_div::loadTCA('tt_content');

$TCA['tt_content']['columns']['CType']['config']['items']['user_my_type'] = array(
  0 => 'My custom content',
  1 => 'user_my_type',
  2 => 'i/tt_content.gif',
);
$TCA['tt_content']['ctrl']['typeicon_classes']['user_my_type'] = 'mimetypes-x-content-text';
$TCA['tt_content']['ctrl']['typeicons']['user_my_type'] = 'tt_content.gif';

/* In the following either copy, insert and modify configuration from some other
   content elemenet (you can find it in the ADMIN TOOLS -> Configuration - $TCA)... */
$TCA['tt_content']['types']['user_my_type']['showitem'] = '';

/* ...or assign it some other configuration so that it's exactly the same
   as some other content type and stays the same after some update of TYPO3: */
$TCA['tt_content']['types']['user_my_type']['showitem'] = $TCA['tt_content']['types']['text']['showitem'];

After that, just set in your Typoscript template how the element is supposed to be rendered:

tt_content.user_my_type = COA
tt_content.user_my_type {
  10 = TEMPLATE
  10 {
    template = TEXT
    template.field = header

    marks {
      MY_MARKER = TEXT
      MY_MARKER.value = TEST
    }
  }

  20 = TEMPLATE
  20 {
    template = TEXT
    template {
      field = bodytext
      required = 1
      parseFunc = < lib.parseFunc_RTE
    }

    marks < tt_content.user_my_type.10.marks
  }
}

NOTES

  1. The Typoscript rendering is just a simplified example. You might want to add other standard configuration like in other elements, e.g. the one that adds edit icons for frontend display.
  2. The marker in my example can be populated by the value of a GET paramater in the URL as you wanted but this would have nasty security implications. You would certainly need very good validation of that input.

Upvotes: 1

Related Questions