IF Else Abfrage für ein Content Block?

Diskussionen zur Smarty-Template-Engine
Post Reply
dalton
Forum Members
Forum Members
Posts: 45
Joined: Fri Feb 19, 2010 8:30 am

IF Else Abfrage für ein Content Block?

Post by dalton »

Hallo

Ich habe {content block="Banner"} im Template eingebaut damit man ein beliebigen Banner für jede Seite einfügen kann nur muss man dann bei allen Seiten die man hat den Banner einzeln hinzufügen egal ob vorerst überall der Gleiche ist oder nicht.

Meine Frage ist kann ich im Template eine IF Else abfrage starten das heisst wen im {content block="Banner"} kein Inhalt vorhanden ist einfach ein von mir ausgewählten Banner als Standart kommt?

In dieser Art mein ich das:

Code: Select all

{if content block="Banner"->value ==''}
{content block="Banner"}
{else}
<img src="standartbanner.jpg">
{/if}
Nur leider funktioniert das nicht so einfach.

mfg
nockenfell
Power Poster
Power Poster
Posts: 751
Joined: Fri Sep 12, 2008 2:34 pm
Location: Schweiz / Switzerland

Re: IF Else Abfrage für ein Content Block?

Post by nockenfell »

Du kannst es damit versuchen:

Code: Select all

{* Content Block Banner der Variable $banner zuordnen *}
{content block="Banner" assign="banner"}

{* Abfrage was angezeigt werden soll *}
{if $banner != ""}
{$banner}
{else}
<img src="standartbanner.jpg">
{/if}
[this message is written with 100% recycled bits]
dalton
Forum Members
Forum Members
Posts: 45
Joined: Fri Feb 19, 2010 8:30 am

Re: IF Else Abfrage für ein Content Block?

Post by dalton »

Super genau das hab gemeint.

Vielen Dank für die schnelle Antwort :)
nockenfell
Power Poster
Power Poster
Posts: 751
Joined: Fri Sep 12, 2008 2:34 pm
Location: Schweiz / Switzerland

Re: IF Else Abfrage für ein Content Block?

Post by nockenfell »

Dies müsste funktionieren:

Code: Select all

{content assign="inhalt"}
{if $inhalt != ""}
{inhalt}
{else}
{menu loadprops=0 template='minimal_menu.tpl'  start_level="2"}
[/quote]
[this message is written with 100% recycled bits]
nockenfell
Power Poster
Power Poster
Posts: 751
Joined: Fri Sep 12, 2008 2:34 pm
Location: Schweiz / Switzerland

Re: IF Else Abfrage für ein Content Block?

Post by nockenfell »

Fehler geschrieben. Es muss {$inhalt} heissen und nicht {inhalt}. Die Anführungszeichen habe ich auch geändert. Diese könnten ev eine Rolle spielen.

Code: Select all

{content assign='inhalt'}
{if $inhalt != ''}
{$inhalt}
{else}
{menu loadprops=0 template='minimal_menu.tpl'  start_level="2"}
[/quote]
[this message is written with 100% recycled bits]
klenkes
Power Poster
Power Poster
Posts: 307
Joined: Mon Sep 08, 2008 9:43 am

Re: IF Else Abfrage für ein Content Block?

Post by klenkes »

Code: Select all

{content assign='inhalt'}
{if $inhalt != ''}
{$inhalt}
{else}
{menu loadprops=0 template='minimal_menu.tpl'  start_level="2"}
{/if}
Und natürlich das schliessende /if

--
Bernd
Last edited by klenkes on Fri Dec 10, 2010 9:34 am, edited 1 time in total.
uniqu3

Re: IF Else Abfrage für ein Content Block?

Post by uniqu3 »

@M@t

{if !empty($foo)}
{$foo}
{else}
Sonst was
{/if}

Obwohl wenn ich mich nicht täusche, muss im Backend im "Content" also "Inhalt" Feld immer was eingegeben werden, daher glaube ich nicht das Du Seite als leer anlegen kannst, außer Du verwendest dafür ein Content Block.
Last edited by uniqu3 on Thu Dec 16, 2010 10:40 am, edited 1 time in total.
Post Reply

Return to “Smarty-Tipps und -Tricks”