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

Mehrere Variablen ansprechen

 
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
Freaky
Smarty n00b


Joined: 20 May 2016
Posts: 3

PostPosted: Fri May 20, 2016 1:48 pm    Post subject: Mehrere Variablen ansprechen Reply with quote

Hallo,

ich habe eine Frage zu Variablen.
Und zwar möchte ich mehrere Variablen nicht anzeigen lassen.
Dazu verwende ich folgenden Code:
Code:
$Merkmal->cName!="Test"


Jetzt gibt es bei mir aber mehrere Variablen die ich nicht angezeigt haben möchte, z.B. "Test1" bis "Test10"

Kann ich jetzt irgendwie die Variable "Test*" nennen, damit alle nicht angezeigt werden die mit "Test" anfangen?

Das Beispiel mit dem Stern klappt leider nicht. Alternativ müsste ich halt jede Variable ausschließen, das wären recht viele.

Danke schon mal!
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Mon May 23, 2016 6:32 am    Post subject: Reply with quote

Hey,

es gibt da sehr viele Möglichkeiten. Zum Beispiel kannst du ja mit "Starts With" machen und der php Methode strrpos

Code:

strrpos($deinText, $startetMitText, -strlen($deinText)) !== false


oder mit RegEx da hast du den Vorteil mit dem "*":

Code:
preg_match("/Test*/", $input_line, $output_array);


oder eben mit dem, was dir nicht gefällt

Code:
$t == "Test1" || $t == "Test2" ...


Theoretisch könnte man auch auf "enthält" prüfen...
Back to top
View user's profile Send private message Visit poster's website
Freaky
Smarty n00b


Joined: 20 May 2016
Posts: 3

PostPosted: Mon May 23, 2016 5:57 pm    Post subject: Reply with quote

Hallo Grizzly,

danke für Deine Mühe!

Ich hatte natürlich vergessen zu erwähnen dass sich die genannte Variable in einer .tpl Datei befindet. Da kann ich natürlich keinen php Code einbinden, bzw. müsste diesen per externer Datei einbinden.

Über Smarty direkt scheint es dann wohl nur die letzte Möglichkeit zu geben!? Confused
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Tue May 24, 2016 5:49 am    Post subject: Reply with quote

Ne, das geht auch alles direkt im Template. Theoretisch kann man alles was man im PHP-Code macht, auch im Template machen

strpos:

Code:
{if $value|strpos:"Test" != 0}...{/if}


preg_match:

http://www.smarty.net/forums/viewtopic.php?p=77534
Back to top
View user's profile Send private message Visit poster's website
Freaky
Smarty n00b


Joined: 20 May 2016
Posts: 3

PostPosted: Wed May 25, 2016 2:35 pm    Post subject: Reply with quote

Hallo Grizzly,

vielen Dank für Deine Hilfe!
Damit komme ich erst mal weiter Wink
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