Externe Inhalte in Smarty Templates einbinden
Wie bindet man Scripte und Texte von externen Domains in Smarty Templates ein?
Dafür gibt es unterschiedliche Ansätze.
Externes PHP-Scripte können so eingebunden werden:
{php}
include ("http://www.domain.de/script.php");
{/php}
include ("http://www.domain.de/script.php");
{/php}
Natürlich können auch Variablen an das externe Script übergeben werden.
Externes PHP Script mit Variable $title aus dem Smarty Template:
{php}
 $keywords =& $this->get_template_vars('title');
 include ("http://www.domain.de/script.php?parameter=$keywords");
{/php}
 $keywords =& $this->get_template_vars('title');
 include ("http://www.domain.de/script.php?parameter=$keywords");
{/php}
Ein Textfile kann einfach eingebunden werden, wenn 'fopen wrappers' in PHP erlaubt ist:
{php}
 $content=file_get_contents("http://www.domain.de/textfile.txt");
 echo $content;
{/php}
 $content=file_get_contents("http://www.domain.de/textfile.txt");
 echo $content;
{/php}
Sollte aber 'fopen wrappers' in PHP deaktiviert sein, muss über Umwege die Datei geholt werden. Zum Beispiel mit CURL:
{php}
 $URL = "http://www.domain.de/textfile.txt";
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$URL);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 $content = curl_exec($ch);
 unset($ch);
 echo $content;
{/php}
 $URL = "http://www.domain.de/textfile.txt";
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$URL);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 $content = curl_exec($ch);
 unset($ch);
 echo $content;
{/php}

Loading ...