[TYPO3-german] Re: PHP-Ausgabe im Template

Hans Meier hans.meier2008 at hotmail.de
Wed Nov 16 17:57:50 CET 2016


Vielen Dank an Alle für Eure Hinweise!

Ich habe es jetzt mit Unterstützung folgendermaßen gelöst:

in PHP eine class 'class_user_spruch.php' angelegt

<?php  

class user_spruch{
	
function hole_spruch(){
	
//Create the connection  
 
$con = mysqli_connect("HOST","USER","PASSWORT","DATENBANK") or die("Some error occurred during connection " . mysqli_error($con));  
 
// Write query
 
$strSQL = "SELECT spruch FROM spruch_des_tages ORDER BY RAND(NOW()) LIMIT 1";
 
// Execute the query.
 
$query = mysqli_query($con, $strSQL);
while($result = mysqli_fetch_array($query)){
  $content = $result["spruch"]."";
}
 
// Close the connection
mysqli_close($con);
return $content;
} 

}
?>

und im typoscript eingebunden

# Default PAGE object:
page = PAGE
page {
  10 = TEMPLATE
  10 {
    template = FILE
    template.file = {$template_path}index.php
    workOnSubpart = DOCUMENT
    marks {
      SPRUCH = USER_INT
      SPRUCH.userFunc = user_spruch->hole_spruch
      SPRUCH.includeLibs = {$template_path}php/class_user_spruch.php
    }
    # marks
  }
  # 10
}
# page

Im Template wird dann über den Marker SPRUCH der Rückgabewert der $content ausgegeben.

Gruß

Hansi


More information about the TYPO3-german mailing list