Hooks und InsertTags
in Contao(4)

Oliver Reiff, trilobit GmbH

Hooks und InsertTags
in Contao(4)

In eigener Sache
Wer bin ich?

In eigener Sache

Wer bin ich?

{{insert::tags}}
Was ist das?

Insert Tags

Simple Ersetzungen

Aber wozu?

Insert Tags

Echte Variablen

Insert Tags

Daten aus tl_page

Insert Tags

Daten aus tl_member

Insert Tags

Include-Elemente

{{insert::tags}}
=Textersetzung

Insert Tags

A box in a box

Insert Tags

A box and a box in a box

{{insert::tags}}
Dos and Don'ts

Insert Tags

Konventionen

Insert Tags

Guter Stil

Insert Tags

Naja, geht auch

Insert Tags

InsertTags in der Programmierung auflösen

\Controller::replaceInsertTags('{{date}}');

Warum?

Insert Tags

Besondere InsertTags

{{iflng::en}}Your name{{iflng::de}}Ihr Name{{iflng}}
{{iflng::en}}Your name{{iflng::de}}Ihr Name{{iflng}}

Eigene
{{insert::tags}}

Insert Tags

Do it yourself!

// config.php
$GLOBALS['TL_HOOKS']['replaceInsertTags'][] = array('MyClass', 'myReplaceInsertTags');
// MyClass.php
public function myReplaceInsertTags($strTag) {
  if ($strTag == 'mytag') {
    return 'mytag replacement';
  }
  return false;
}

Just one more thing...

Flags

Weitere Flags siehe https://docs.contao.org/books/manual/4.4/de/04-inhalte-verwalten/inserttags.html

Hook,
ich habe gesprochen.

Hooks allgemein

Mit Haken und Ösen

Beliebte Hooks

  • activateAccount
  • activateRecipient
  • closeAccount
  • createNewUser
  • generateBreadcrumb
  • generatePage
  • getSearchablePages
  • postLogin / postLogout
  • processFormData
siehe https://docs.contao.org/books/api/extensions/hooks/

Code-Skelett - bis Contao 4.4
(ab 4.5 zusätzlich tagged services)

// config.php
$GLOBALS['TL_HOOKS'][<HookName>][] = array(<MyClass>, <myMethod>);
// <MyClass>.php
public function <myMethod>($params) {
  ....
  return $res;
}

Typische Anwendungsfälle

trilobit GmbH