Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

params ohne ="" übergeben möglich??

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
Paykoman
Smarty Rookie


Joined: 07 May 2011
Posts: 34

PostPosted: Wed Sep 18, 2013 11:30 am    Post subject: params ohne ="" übergeben möglich?? Reply with quote

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 Smile

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Wed Sep 18, 2013 5:06 pm    Post subject: Reply with quote

{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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP