|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
janw1 Smarty n00b
Joined: 19 Jan 2017 Posts: 3
|
Posted: Thu Jan 19, 2017 2:26 pm Post subject: Problem mit registerPlugin |
|
|
Hallo,
ich bekomme immer einen Synatx-Error, wenn ich meine Smarty-Dateien compiliere.
Nämlich " Syntax error in template "/home/list.tpl" on line 100 "{writeBannerStatistics($bannerParams)}" unknown function "writeBannerStatistics""
In der index.php registriere ich das Plugin wie folgt:
$smarty->registerPlugin("function", "writeBannerStatistics", "writeBannerStatistics");
Die Function an sich liegt in der Datei phpFunction.php, die ich beim Start einbinde und sieht so aus:
Code: | function writeBannerStatistics( $bannerParams){
$bannerId = $bannerParams[0];
$bannerAction = $bannerParams[1];
...
} |
In meiner tpl-Datei rufe ich das dann so auf
Code: | {writeBannerStatistics($params)} |
In den Beispielen finde ich immer mal, dass der Kopf der Function so programmiert ist im PHP-Skript:
Code: | function writeBannerStatistics( $bannerParams, $smarty){ |
wobei nie erklärt wird, warum da ein $smarty mit angegeben wird. Denn beim Aufrufen wird in den Beispielen nie eine zweite Variable übergeben.
Ich finde einfach nicht meinen Fehler. Wisst ihr evtl Rat?
Danke
Jan |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Jan 22, 2017 8:45 am Post subject: |
|
|
Please read documentation and supplied examples again.
You're using wrong syntax in your template. |
|
Back to top |
|
janw1 Smarty n00b
Joined: 19 Jan 2017 Posts: 3
|
Posted: Mon Jan 23, 2017 11:38 am Post subject: |
|
|
???
Ich habe genau die Syntax aus der Doku verwendet.
Der Witz ist ja auch, dass die Funktion ausgeführt wird, aber trotzdem beim Compilen der Syntax Error angezeigt wird..
PS: ist auch nicht sehr hilfreich, wenn im deutschen Forum auf englisch geantwortet wird und die Antwort leider keinen Aufschluss über den Fehler gibt. Dass ich die "Wrong syntax" verwende, sagt mir ja schon der Compiler. Nur was falsch ist, das ist das, was ich gern wissen möchte... |
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Mon Jan 23, 2017 12:23 pm Post subject: |
|
|
Hallo,
wenn du dir hier mal die Dokumentation ansachaust: Register PlugIn
wirst du feststellen dass:
1. die Funktion schon den zweiten Parameter benötigt (auch wenn du den nicht verwendest)
und 2.
solltest du nicht so:
Code: | {writeBannerStatistics($params)} |
den Aufruf machen sondern so:
Code: | {writeBannerStatistics IrgendEinName=$params} |
Somit kannst du dann in deinem Code folgendes tun:
Code: |
function writeBannerStatistics( $params, $smarty){
$bannerParams = $params["IrgendEinName"];
$bannerId = $bannerParams[0];
$bannerAction = $bannerParams[1];
...
}
|
ich hoffe das hilft |
|
Back to top |
|
janw1 Smarty n00b
Joined: 19 Jan 2017 Posts: 3
|
Posted: Mon Jan 23, 2017 1:01 pm Post subject: |
|
|
Ah, ok. Das ist mal ein Ansatz, der mir auf die Sprünge hilft.
Vielen Dank! |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|