+ All Categories
Home > Technology > FLOW3, Extbase & Fluid cook book

FLOW3, Extbase & Fluid cook book

Date post: 19-May-2015
Category:
Upload: bastian-waidelich
View: 3,429 times
Download: 5 times
Share this document with a friend
Description:
Slides from my talk at T3CON12CA.See https://github.com/bwaidelich/Extensions.my_website_com and https://github.com/bwaidelich/Extensions.books for the corresponding TYPO3 Extensions.
Popular Tags:
30
FLOW3, Extbase & Fluid cook book June 15th 2012, Québec
Transcript
Page 1: FLOW3, Extbase & Fluid cook book

FLOW3, Extbase & Fluid cook book June 15th 2012, Québec

Page 2: FLOW3, Extbase & Fluid cook book

Bastian Waidelich

Page 3: FLOW3, Extbase & Fluid cook book
Page 4: FLOW3, Extbase & Fluid cook book

2002 2008

Page 5: FLOW3, Extbase & Fluid cook book

THEORY

Page 6: FLOW3, Extbase & Fluid cook book

D D D

Page 7: FLOW3, Extbase & Fluid cook book

omain riven esign D D D

Page 8: FLOW3, Extbase & Fluid cook book

MODEL MODEL MODEL

Page 9: FLOW3, Extbase & Fluid cook book

Y R D

Page 10: FLOW3, Extbase & Fluid cook book

on‘t epeat ourself Y R D

Page 11: FLOW3, Extbase & Fluid cook book

Duplication is evil

Page 12: FLOW3, Extbase & Fluid cook book

S S I K

Page 13: FLOW3, Extbase & Fluid cook book

tupid imple t eep S S I K

Page 14: FLOW3, Extbase & Fluid cook book

In Phoenix: „MyWebsiteCom“

1. Put your site in an Extension/Package

Protect private folders with .htaccess files:

deny from all

Page 15: FLOW3, Extbase & Fluid cook book

2. Use Fluid for your site template

page = PAGE page { typeNum = 0 10 = FLUIDTEMPLATE 10 { file = EXT:my_website_com/Resources/Private/Templates/Site.html extbase.controllerExtensionName = MyWebsiteCom } }

page = PAGE page { typeNum = 0 10 = FLUIDTEMPLATE 10.file = EXT:my_website_com/Resources/Private/Templates/Site.html }

Specify extension name/package key for localisation & resources

page = TYPO3.TYPO3:Page page.body.templatePath = 'resource://MyWebsiteCom/Private/Templates/Site.html'

Phoenix:

Page 16: FLOW3, Extbase & Fluid cook book

DEMO

Page 17: FLOW3, Extbase & Fluid cook book

3. Layouts

page { … 10 = FLUIDTEMPLATE 10 { … file = CASE file { key.data = levelfield:-1,backend_layout_next_level,slide key.override.field = backend_layout default = TEXT default.value = EXT:my_website_com/…/Default.html 2 = TEXT 2.value = EXT:my_website_com/…/Wide.html } }

Solution 1: different templates

Page 18: FLOW3, Extbase & Fluid cook book

3. Layouts

page { … bodyTagCObject = CASE bodyTagCObject { key.data = levelfield:-1,backend_layout_next_level,slide key.override.field = backend_layout default = TEXT default.value = <body> 2 = TEXT 2.value = <body class="wide"> } }

Very clean, but not always possible

Solution 2: CSS

Page 19: FLOW3, Extbase & Fluid cook book

3. Layouts

10 { … variables { … layout = CASE layout { key.data = levelfield:-1,backend_layout_next_level,slide key.override.field = backend_layout default = TEXT default.value = Default 2 = TEXT 2.value = Wide } } }

Solution 3: Partials

<f:render partial="Content{layout}" />

Site.html

Page 20: FLOW3, Extbase & Fluid cook book

DEMO

Page 21: FLOW3, Extbase & Fluid cook book

Extension Package

Page 22: FLOW3, Extbase & Fluid cook book

4. Continuously enhance model

String comparison will be possible in Fluid! But it‘s mostly not needed.

<f:if condition="{paper.status} == 'accepted'"> <p>{paper.title} is accepted</p> </f:if> This will will not work!

Templates/Paper.html

Page 23: FLOW3, Extbase & Fluid cook book

4. Continuously enhance model

/** * @return boolean */ public function isAccepted() { return $this->status === self::STATUS_ACCEPTED; }

Model/Paper.php

<f:if condition="{paper.accepted} "> <p>{paper.title} is accepted</p> </f:if>

Templates/Paper.html

Page 24: FLOW3, Extbase & Fluid cook book

DEMO

Page 25: FLOW3, Extbase & Fluid cook book

5. Encapsulate your hacks

public function tagCloudAction() { $books = $this->bookRepository->findAll(); $tags = array(); foreach ($books as $book) { foreach ($book->getTags() as $tag) { $tagCount = 1; if (isset($tags[$tag->getTitle()])) { $tagCount ++; $tags[$tag->getTitle()] = $tagCount; } } $this->view->assign(tags, $tags); }

Controller/BookController.php

Page 26: FLOW3, Extbase & Fluid cook book

5. Encapsulate your hacks

public function tagCloudAction() { $tags = $this->tagCloudService->createTagCloud()); $this->view->assign('tags', $tags); }

Controller/BookController.php

<f:for each="{tags}" as="tag"> <span class="tag popularity-{tag.popularity}"> {tag.name} </span> </f:for>

Book/TagCloud.html

TagCloudService interacts with Database directly

Page 27: FLOW3, Extbase & Fluid cook book

DEMO

Page 28: FLOW3, Extbase & Fluid cook book

6. Performance

CACHING!

TCEMAIN.clearCacheCmd = 1,2,3

Storage folder TSConfig:

AJAX!

Page 29: FLOW3, Extbase & Fluid cook book

DEMO

Page 30: FLOW3, Extbase & Fluid cook book

THANK YOU @bwaidelich github.com/bwaidelich


Recommended