PHP Code Integration

Bis TYPO3 Version 6.0 ging das noch einfach...

Ins Setup eines TS Templates folgenden Code einfügen:

includeLibs.user_test = fileadmin/scripts/test.php
lib.phpskript = USER
lib.phpskript.userFunc = user_test->out

Die Datei fileadmin/scripts/test.php sieht dann folgendermaßen aus:

<?php
class user_test {
  function out() {
    return 'PHP output';
  }
}

Aber includeLibs wird nicht mehr unterstützt.

Erstellt: 09/2015| Geändert: 03/2023

Aktuelle TYPO3 Versionen

Es ist immer noch möglich, aber man benötigt eine Extension dazu, hier die RsystemplateBootstrap:

In Typoscript definieren. Hier ohne Cache. Mit Cache wäre es USER statt USER_INT

lib.TEST= USER_INT
lib.TEST{
  userFunc = RSYS\RsystemplateBootstrap\UserFunctions\Phpcode->main
}

In Classes/UserFunctions/Phpcode.php

<?php
namespace RSYS\RsystemplateBootstrap\UserFunctions;
final class Phpcode{
    public function main(string $content, array $conf): string {
        return "TEST OUTPUT";
    }
}

Ist an sich auch einfach. Aber eleganter ist es mit Controllern und Model usw in TYPO3 zu arbeiten, ist aber auch wesentlich komplizierter.

Weitere Beispiele unter https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/ContentObjects/UserAndUserInt/Index.html

 

Erstellt: 03/2023| Geändert: 03/2023