|
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 |
Paykoman Smarty Rookie
Joined: 07 May 2011 Posts: 34
|
Posted: Wed Sep 18, 2013 11:30 am Post subject: params ohne ="" übergeben möglich?? |
|
|
Hallöchen,
in meinem Script gibt es eine simple _GET Anweisung um eine bestimmte Ausgabe zu erhalten: "?onlycontent=true".
In Smarty habe ich mir jetzt ne kleine Funktion geschrieben um hier die .tpl sauberer zu halten und natürlich um weniger schreiben zu müssen
Wie ihr wisst sind Programmierer ja faul *g*, nun hätte ich gerne gewusst ob es hier eine Möglichkeit gibt in der Funktion ohne ein ="" am ende des params zu schreiben diesen trotzdem zu senden?
Smarty spuckt da immer Syntax-Fehler aus =(
Im Template:
Quote: | {if {isOC bool=""} == true}ja{/if} |
smarty.function:
Quote: | function smarty_function_isOC($params, $template)
{
global $smarty;
if( isset($params['bool']) )
{
return (isSubmit('onlycontent', 'get')) ? true : false;
}
else
{
echo (isSubmit('onlycontent', 'get')) ? '&onlycontent=true' : '';
}
} |
Wäre ja schön wenn ich im Template nur ein {isOC bool} schreiben könnte =)
MFG: Pay |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Sep 18, 2013 5:06 pm Post subject: |
|
|
{isOC bool} geht nicht.
Außerdem hat
Quote: | {if {isOC bool=""} == true}ja{/if} |
noch einen Schöheitsfehler.
Der return Wert eines plugins wird immer als Output per echo bearbeitet. Über Umwege kommt das Resultat per echo true bwz echo false in Deine if abfrage. Du vergleichst also keine boolean Werte.
Andererseits hat ein echo im plugin nichts zu suchen.
Sauber wäre das Plugin
Code: | function smarty_function_isOC($params, $template)
{
return (isSubmit('onlycontent', 'get')) ? '&onlycontent=true' : '';
}
|
für die Benutzung im Template außerhalb {if}
Und eine PHP Funktion
Code: | function isOC () {
return (isSubmit('onlycontent', 'get')) ? true : false;
}
|
Die Du als {if isOC() == true} aufrufen kannst. |
|
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
|