35
In2code.de Wir leben TYPO3 In2code. Wir leben TYPO3 IF, CASE, CONDITION TypoScript

TYPO3 TypoScript: IF, CASE, CONDITIONS

Embed Size (px)

DESCRIPTION

in2code TYPO3: Ausführliche TypoScript Beispiele zu if-Bedingungen, CASE und Conditions mit Praxisbeispielen

Citation preview

Page 1: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3 In2code.

Wir leben TYPO3

IF, CASE, CONDITIONTypoScript

Page 2: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

1.TypoScript Einführung

2.Conditions

3.CASE

4.IF

5.Links

Page 3: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

TypoScript Einführung

Page 4: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

Was ist TypoScript?

TypoScript ist eine Konfigurationssprache die TYPO3 anweist, Daten zu verarbeiten und anzuzeigen (vergleichbar mit XML).

Diese Konfigurationssprache ist eines der Hauptmerkmale bei der Unterscheidung von TYPO3 zu einem anderen CMS.

Vorteil: TYPO3 wird somit extrem flexibel

Nachteil: TypoScript bietet eine gewisse Lernhürde

Page 5: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

page = PAGEpage.10 = TEXTpage.10.value = Hello World

Hello WorldHello World <html>

setup

Schritt 1: Statischen Text ausgeben

Page 6: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

page = PAGEpage.10 = TEMPLATEpage.10.template = FILEpage.10.template.file = fileadmin/htmltemplate.html

Hello World

Info: TEMPLATE generiert HTML Head und erlaubt ersetzen von Subparts und Markern

<html><head>…</head><body>

Hello World</body></html>

<html>

setup

Schritt 2: Statischen Text aus HTML Template ausgeben

Page 7: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

page = PAGEpage.10 = TEMPLATEpage.10 {

template = FILEtemplate.file = fileadmin/htmltemplate.htmlmarks.MARKER = TEXTmarks.MARKER.value = Ich bin ein Marker

}

Hello WorldIch bin ein Marker

…Hello World<br />Ich bin ein Marker…

<html>

setup

Schritt 3: HTML Template mit Marker ausgeben

Page 8: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

page = PAGEpage {

10 = TEXT10.value = {$var}20 = TEXT20.value = {$var}30 < .10…

setup

Hello WorldHello WorldHello WorldHello WorldHello WorldHello World<html>

var = Hello Worldconstants

Schritt 4: Konstanten nutzen

Page 9: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

TypoScript Conditions

Page 10: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

Was sind TypoScript Conditions?

Conditions sind Bedingungen, die bei Erfüllung eine bestimmte TS Konfiguration zulassen oder ignorieren.

Gängige Bedingungen:

browser, IP, month, usergroup, PIDupinRootline, globalVar, userFunc

Page 11: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

page.10 = TEXTpage.10.value = Hello World

[globalVar = GP:L=1]page.10.value = Hallo Welt[end]

Info: Conditions nie innerhalb von geschweiften Klammern nutzen

# index.php?id=1Hello World

<html>

setup

# index.php?id=1&L=1Hallo Welt

<html>

Schritt 5: Conditions nutzen

Page 12: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

page.10 = TEXTpage.10 {

value = lala[globalVar = GP:L=1]

value = lulu[end]}

# immer lalalala

<html>

setup

# index.php?id=1lala

# index.php?id=1&L=1lulu

<html>

page.10 = TEXTpage.10 {

value = lala}

[globalVar = GP:L=1]page.10.value = lulu[end]

setup

Schritt 6: Conditions nie innerhalb von geschweiften Klammern

Page 13: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

page.10 = TEXTpage.10.value = {$var} setup

Info: Conditions können auch in den constants verwendet werden

# SeptemberEs ist Winter

# AugustEs ist Sommer

<html>

[month = 4,5,6,7,8]var = Es ist Sommer[end][month = 9,10,11,12,1,2,3,4]var = Es ist Winter[end]

constants

<html>

Schritt 7: Weitere Condition Beispiele (month)

Page 14: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

page.10 = TEXTpage.10.value = Diese Seite ist noch in der Entwicklung[IP = 192.168.*.*]page.10 = TEMPLATEpage.10.template.file = fileadmin/template.html...[end]

setup

# IntranetAnything else

# InternetDiese Seite ist noch in der Entwicklung

<html> <html>

Schritt 8: Weitere Conditions Beispiele (IP)

Page 15: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

# clear subpartpage.10.subparts.RECHTESPALTE = COApage.10.subparts.RECHTESPALTE {

10 = TEXT20 = TEXT30 = TEXT

}

# show if on PID 1[globalVar = TSFE:id=1]page.10.subparts.RECHTESPALTE.10.value = Du bist auf Home[end]

# if news detail is shown[globalVar = GP:tx_ttnews|tt_news > 0]page.10.subparts.RECHTESPALTE.20.value = News powered by TYPO3[end]

# if powermail mail was sent[globalVar = GP:tx_powermail_pi1|uid40 = *]page.10.subparts.RECHTESPALTE.10.value = Mail wurde abgesendet![end]

setup

Schritt 9: Weitere Conditions Beispiele (globalVar)

Page 16: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

[userFunc = user_test]# do something[else]# do something else[end]

setup

Info: Keine Klassen, nur Funktionen

function user_test() { if (date('m') == '01') {

return true; } else {

return false;}

}

<php> …include 'fileadmin/userFunc.php';…

localconf

Schritt 10: Weitere Conditions Beispiele (userFunc)

Page 17: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

TypoScript CASE

Page 18: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

CASE in TypoScript

Ähnlich der SWITCH Funktion in PHP, kann man mit CASE einen Parameter auf verschiedene Werte vergleichen.

Sinn:

ist A gleich B, dann X, wenn nicht, ist A gleich C, dann Y, wenn nicht,ist A gleich D, dann Z

Schnelle Abarbeitung möglich

Page 19: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

# page.subtitle could be 1 or 2 or 3lib.object = CASElib.object {

key.field = subtitle

default = TEXTdefault.value = Das ist eine Standardseite

2 = TEXT2.value = Hier finden sie die besten News

3 = TEXT3.value = Hier zeigen wir Ihnen tolle Fotos

}

Page.10.marks.OBJECT < lib.object

setup

Schritt 11: CASE anwenden

Page 20: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

# wrap header of a content element…10 = CASE10 {

key.field = header_layout

1 = TEXT1.fontTag = <h1>|</h1>

2 < .12.fontTag = <h2>|</h2>

3 < .13.fontTag = <h3>|</h3>

}…

setup

Schritt 12: CASE anwenden (von css_styled_content)

Page 21: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

Details: http://www.typo3.net/index.php?id=13&action=list_post&tid=78897

object = CASEobject {

key.data = TSFE:fe_user|sesData|powermail_5345|uid34

default = TEXTdefault.value = Sehr geehrte Frau

Herr = TEXTHerr.value = Sehr geehrter Herr

}

plugin.tx_powermail_pi1.dynamicTyposcript.test < object

setup

Schritt 13: CASE anwenden (von powermail)

Page 22: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery ('title, description, url','tx_jump_url', '1', '', '', 1

);while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {

foreach ($row as $key => $value) {$this->cObj->start(array('table'=>$key,'value'=>$value),

'table');$marker['###' . strtoupper($key) . '###'] =

$this->cObj->cObjGetSingle($conf['temp'], $conf['temp.']);

}}

<php>

temp = CASEtemp {

key.field = tabledefault = TEXTdefault.field = valueurl < .defaulturl.typolink.parameter.field = url

}

setup

Schritt 14: CASE anwenden (Extensionentwicklung)

Page 23: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

TypoScript if

Page 24: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

Was ist eine IF Abfrage in TypoScript?

TypoScript IF lässt sich nur bedingt mit einer IF-Abfrage in PHP Vergleichen. Annähernd lassen sich jedoch auch hier bedingte Ausführungen von TypoScript realisieren.

Gängige IF Statements in TypoScript:

isTrue, isFalse, isPositive, isGreaterThan, isLessThan, equals, isInList, value, negate, directReturn

Page 25: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

# title: lib.title = TEXTlib.title.field = titlelib.title.wrap = <b>Titel: |</b>

setup

Info: Leerzeichen im Wrap mit noTrimWrap

Titel:Titel: Seite1

# title: Seite1lib.title = TEXTlib.title.field = titlelib.title.wrap = <b>Titel: |</b>

setup

Schritt 15: Wrap immer vorhanden!?

Page 26: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

# title: Seite1lib.title = TEXTlib.title {

field = titlefield.wrap = <b>Titel: |

</b> if.isTrue.field = title

}

setup

Titel: Seite1

# title:lib.title = TEXTlib.title {

field = titlefield.wrap = <b>Titel: |

</b> if.isTrue.field = title

}

setup

Schritt 16: Wrap nur wenn Inhalt (Wenn)

Page 27: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

lib.title COAlib.title {

10 = TEXT10.field = title10.if.isTrue.field = title20 = TEXT20.value = Kein Titel für diese Seite vergeben20.if.isFalse.field = title

}

setup

Seite 1 Kein Titel für diese Seitevergeben

Schritt 17: Anderer Inhalt wenn Feld leer (COA: Wenn, Dann)

Page 28: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

temp.maintemplate = COAtemp.maintemplate {

# if there is content in the right col10 = COA10 {

if.isTrue.numRows < styles.content.getRight10 = TEMPLATE10 {

template = FILEtemplate.file = fileadmin/2cols.html

}}

# if there is NO content in the right col20 = COA20 {

if.isFalse.numRows < styles.content.getRight10 = TEMPLATE10 {

template = FILEtemplate.file = fileadmin/1col.html

}}

}

setup

Schritt 18: Praxisbeispiel – Anderes HTML Template bei Wert in rechter Spalte

Page 29: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

page.10 = TEMPLATEpage.10 {

template = FILEtemplate.file = fileadmin/tmpl.html

subparts.CONTENT = COAsubparts.CONTENT {

10 = COA10 {

if.isTrue.numRows < styles.content.getLeft10 < styles.content.getLeft10.wrap = <div id="col1" class="col">|</div>20 < styles.content.get20.wrap = <div id="col2" class="col">|</div>

} 20 = COA

20 {if.isFalse.numRows < styles.content.getLeft10 = TEXT20 < styles.content.get20.wrap = <div id="col12">|</div>

}

}}

setup

Schritt 18: Praxisbeispiel – Automatisch Zwei-Spaltig durchanderen Wrap

Page 30: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

lib.foo = TEXTlib.foo {

value = News mit UID 2if.value.data = GPvar:tx_ttnews[tt_news]if.equals = 2

}

setup

# &tx_ttnews[tt_news]=1 # &tx_ttnews[tt_news]=2News mit UID 2

Schritt 19: if mit equals

Page 31: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

lib.foo = COAlib.foo {

10 = TEXT10.value = News mit UID 210.if.value.data = GPvar:tx_ttnews[tt_news]10.if.equals = 2

20 = TEXT20.value = Andere News20.if.value.data = GPvar:tx_ttnews[tt_news]20.if.equals = 220.if.negate = 1

}

setup

# Gleiches Resultat mit CASElib.foo = CASElib.foo {

key.data = GPvar:tx_ttnews[tt_news]default = TEXTdefault.value = Andere News2 = TEXT20.value = News mit UID 2

}

setup

Schritt 20: negate

Page 32: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

lib.menu = HMENUlib.menu {

1 = TMENU1 {

NO {stdWrap.cObject = COAstdWrap.cObject {

10 = TEXT10.field = title10.if {

value.field = uidequals.data =

GPvar:tx_finder_pi1|page}10.wrap = <b>|</b><br />

20 < .1020.if.negate = 120.wrap = |<br />

}}

}}

setup

Schritt 21: Komplexeres BeispielMenü mit ACT Status anhand GET Parameter

Page 33: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

Allgemeine LinksZum Thema

Page 34: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3

• Einführung conditions:http://www.rainer-grundel.de/wissensdb/typo3/allgemein/artikel/article/condition_fuer_typo3_und_oder_verknuepfung.html

• typo3blogger.de (if, case):http://typo3blogger.de/if-abfrage-mit-typoscript/

• typo3blogger.de (Ein- oder zweispaltige Templates): http://typo3blogger.de/automatisch-ein-oder-zweispaltig-ohne-tv-und-ohne-templateselector/

• wiki.typo3.org (if)http://wiki.typo3.org/index.php/De:TSref/if

• wiki.typo3.org (case)http://wiki.typo3.org/index.php/De:TSref/CASE

• conditions TSref 4.3: http://typo3.org/documentation/document-library/references/doc_core_tsref/4.3.0/view/1/4/

Page 35: TYPO3 TypoScript: IF, CASE, CONDITIONS

In2code.deWir leben TYPO3In2code.

Vielen Dank

www.in2code.deStefan BusemannTina GasteigerAlex Kellner