• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: HTML-Tags nur dann, wenn die Variable exisitert
PostPosted: Mon May 17, 2010 11:05 am 
Hier im Forum wurden schon häufig folgende Smarty-Prüfungen für die Anzeige von Variablen empfohlen:

Code:
{if $varname}
<p>
{$varname}
</p>
{/if}


Grundsätzlich korrekt, es geht aber auch kürzer ... mit einem Modifikator

Code:
<?php
function smarty_modifier_wrap($var, $prefix, $suffix)
{
    if (isset($var) && $var != '') $output = $prefix.$var.$suffix;
    return $output;
}
?>


Damit reduziert sich der erste Block auf

Code:
{$varname|wrap:"<p>":"</p>"}


Anstatt der html-Tags kann natürlich auch jeder beliebiger Text verwendet werden ;) ...


Last edited by cyberman on Mon May 31, 2010 7:31 pm, edited 1 time in total.

Top
  
 
 Post subject: Re: HTML-Tags nur dann, wenn die Variable exisitert
PostPosted: Mon May 31, 2010 6:54 pm 
Excellenter Tip!

Gerade bei diesen vielen kleinen Schnippselchen, die amn so verwendet macht das Sinn und gestaltet den Quelltext übersichtlicher.


Top
  
 
 Post subject: Re: HTML-Tags nur dann, wenn die Variable exisitert
PostPosted: Wed Jun 02, 2010 4:45 pm 
Offline
Forum Members
Forum Members

Joined: Mon Feb 02, 2009 6:28 pm
Posts: 25
Location: Paderborn (Deutschland, NRW)
interessant!
Wo muss denn diesen smarty modifier implementieren? Sprich wo muss dieser php Code eingebaut werden, damit er für smarty zur Verfügung steht?

sorry für die Nachfrage
Ludger


Top
 Profile  
 
 Post subject: Re: HTML-Tags nur dann, wenn die Variable exisitert
PostPosted: Thu Jun 03, 2010 10:53 am 
Du speicherst das gepostete Schnipsel in eine Datei namens modifier.wrap.php und lädst ihn in das Verzeichnis /libs/smarty/plugins.

Fertig

http://www.smarty.net/manual/de/plugins.modifiers.php


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


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 post attachments in this forum

Search for:
Jump to:  
A2 Hosting