fluid - templating for professionals - t3con09

Post on 13-May-2015

3.802 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

Fluid is a next-generation templating engine in PHP developed for FLOW3 and TYPO3 in general. After showing the basics, this presentation outlines the advanced features Fluid has.

TRANSCRIPT

Inspiring people toshareFluid - Templating made easy

T3CON09 Frankfurt - 12 September 2009

Fluid - Templating made easy

Sebastian Kurfürst <sebastian@typo3.org>

12.09.2009

Inspiring people toshareFluid - Templating made easy

TYPO3addict

Inspiring people toshareFluid - Templating made easy

TYPO3 v4 and v5

v4 v5

Inspiring people toshareFluid - Templating made easy

Einordnung - v4, v5 - Transition

Inspiring people toshareFluid - Templating made easy

Why are good frameworksimportant?

Inspiring people toshareFluid - Templating made easy

No!

We need onlyEnd-Userfeatures

Inspiring people toshareFluid - Templating made easy

We needEnd-Userfeatures

Inspiring people toshareFluid - Templating made easy

We needDeveloper

features,too!

Inspiring people toshareFluid - Templating made easy

Developing should be fun!

Inspiring people toshareFluid - Templating made easy

Productivity will increase

Inspiring people toshareFluid - Templating made easy

Inspiring people toshareFluid - Templating made easy

What is a Template Engine?

DataDataData Template

Template Engine

DataDatarendered data

Inspiring people toshareFluid - Templating made easy

Inspiring people toshareFluid - Templating made easy

Why another template engine?

Inspiring people toshareFluid - Templating made easy

Inspiring people toshareFluid - Templating made easy

Goals of Fluid

The Zen of Templating

http://www.sxc.hu/photo/821903

simple powerful

The Zen of Templating

http://www.sxc.hu/photo/821903

intuitive easily extensible

http://www.flickr.com/photos/josefstuefer/9699426/

simple, eleganttemplate engine

Help the template writerin many ways

Easy and cleanextensibility

http://www.sxc.hu/photo/338064

Support for different output formats

Inspiring people toshareFluid - Templating made easy

Goals of Fluid

Simple, elegant template engine

support for the template writer in many ways

simple and clean extensibility

different output formats possible

http://www.sxc.hu/photo/816749

CoreConcepts

Inspiring people toshare

$this->view->assign(‘blogTitle’,$blog->getTitle());

<h1>The name of the blog is: {blogTitle}</h1>

Core Concepts

Fluid - Templating made easy

Variables

Inspiring people toshare

$this->view->assign(‘blog’, $blog);

<h1>The name of the blog is: {blog.title}</h1>Author: {blog.author}

Core Concepts

Fluid - Templating made easy

Object Accessors

$blog->getAuthor();

Inspiring people toshare

{namespace f=F3\Fluid\ViewHelpers}

<f:link.action action=“someAction“>

Administration</f:link>

Core Concepts

Fluid - Templating made easy

ViewHelpers namespace declaration

ViewHelper invocation

v5

Inspiring people toshare

{namespace f=Tx_Fluid_ViewHelpers}

<f:link.action action=“someAction“>

Administration</f:link>

Core Concepts

Fluid - Templating made easy

ViewHelpers namespace declaration

ViewHelper invocation

v4

Fluid Core does not contain any output logic, and no control structures!

<f:...>

Every tag is a class!

{namespace f=Tx_Fluid_ViewHelpers}<f:for>...</f:for>

Tx_Fluid_ViewHelpers_ForViewHelper

v4

{namespace f=F3\Fluid\ViewHelpers}<f:for>...</f:for>

F3\Fluid\ViewHelpers\ForViewHelper

v5

{namespace f=F3\Fluid\ViewHelpers}<f:link.action>...</f:link.action>

F3\Fluid\ViewHelpers\Link\ActionViewHelper

v5

Inspiring people toshare

<f:link.action action=“show“ arguments=“{blog: blog, name:

‘Hello’}“> show posting</f:link>

Core Concepts

Fluid - Templating made easy

Arrays

Inspiring people toshare

Core Concepts

Fluid - Templating made easy

Basic Ingredients

Object accessors: {blog.title}

ViewHelpers: <f:for each=“{blog.posts}“ as=“post“>...</f:for>

Arrays

simple loop

Fluid for professionals

v4 v5

Forms

Inspiring people toshare

/** * Displays a form for creating a new blog * * @param F3\Blog\Domain\Model\Blog $newBlog A fresh blog object taken as a basis for the rendering * @return string An HTML form for creating a new blog * @dontvalidate $newBlog */ public function newAction(\F3\Blog\Domain\Model\Blog $newBlog = NULL) { $this->view->assign('newBlog', $newBlog); }

/** * Creates a new blog * * @param F3\Blog\Domain\Model\Blog $newBlog A fresh Blog object which has not yet been added to the repository * @return void */ public function createAction(\F3\Blog\Domain\Model\Blog $newBlog) { $this->blogRepository->add($newBlog); $this->pushFlashMessage('Your new blog was created.'); $this->redirect('index'); }

Fluid for professionals

Fluid - Templating made easy

Forms

Inspiring people toshare

<f:form method="post" action="create" object="{newBlog}" name="newBlog"> <label for="identifier">Identifier<br /> <f:form.textbox property="identifier" id="identifier" /> <br /> <label for="name">Title</label><br /> <f:form.textbox property="title" id="title" /> <br /> <label for="description">Description</label><br /> <f:form.textarea property="description" rows="2" cols="40" id="description" /> <br /> <f:form.submit value="Create blog" /> </f:form></f:section>

Fluid for professionals

Fluid - Templating made easy

Forms

Inspiring people toshare

Code Text

Fluid for professionals

Fluid - Templating made easy

Inspiring people toshare

/** * Displays a form for creating a new blog * * @param F3\Blog\Domain\Model\Blog $newBlog A fresh blog object taken as a basis for the rendering * @return string An HTML form for creating a new blog * @dontvalidate $newBlog */ public function newAction(\F3\Blog\Domain\Model\Blog $newBlog = NULL) { $this->view->assign('newBlog', $newBlog); }

/** * Creates a new blog * * @param F3\Blog\Domain\Model\Blog $newBlog A fresh Blog object which has not yet been added to the repository * @return void */ public function createAction(\F3\Blog\Domain\Model\Blog $newBlog) { $this->blogRepository->add($newBlog); $this->pushFlashMessage('Your new blog was created.'); $this->redirect('index'); }

Fluid for professionals

Fluid - Templating made easy

Forms

Inspiring people toshare

/** * Displays a form for creating a new blog * * @param F3\Blog\Domain\Model\Blog $newBlog A fresh blog object taken as a basis for the rendering * @return string An HTML form for creating a new blog * @dontvalidate $newBlog */ public function newAction(\F3\Blog\Domain\Model\Blog $newBlog = NULL) { $this->view->assign('newBlog', $newBlog); }

/** * Creates a new blog * * @param F3\Blog\Domain\Model\Blog $newBlog A fresh Blog object which has not yet been added to the repository * @return void */ public function createAction(\F3\Blog\Domain\Model\Blog $newBlog) { $this->blogRepository->add($newBlog); $this->pushFlashMessage('Your new blog was created.'); $this->redirect('index'); }

Fluid for professionals

Fluid - Templating made easy

Forms

Inspiring people toshareFluid - Templating made easy

Layouts

Layouts

v4 v5

Inspiring people toshare

<f:layout name="master" /><f:section name="main">

<h1> My content</h1></f:section>

Fluid for professionals

Fluid - Templating made easy

Layouts

Inspiring people toshare

<html> ...<body> <f:render section="main" /></body>

Fluid for professionals

Fluid - Templating made easy

Layouts

Inspiring people toshareFluid - Templating made easy

Custom ViewHelpers

Inspiring people toshare

Custom ViewHelpers

Fluid - Templating made easy

Task: Gravatar ViewHelper

should take an e-mail address and output the gravatar image, if any.

Expected output:<img src=“http://www.gravatar.com/avatar/md5($email).jpg“ />

v4

Inspiring people toshare

Custom ViewHelpers

Fluid - Templating made easy

Task: Gravatar ViewHelper

Expected usage:

{namespace blog=Tx_Blog_ViewHelpers}<blog:gravatar email=“sebastian@typo3.org“ />

v4

Inspiring people toshare

class Tx_Blog_ViewHelpers_GravatarViewHelper extends Tx_Fluid_Core_AbstractViewHelper { public function render() { return ‘Hello World‘; }}

Custom ViewHelpers

Fluid - Templating made easy

1. Create a ViewHelper skeletonv4

Inspiring people toshare

/** * @param string $email The email to render as gravatar */public function render($email) { return ‘http://www.gravatar.com/gravatar/‘ . md5($email);}

Custom ViewHelpers

Fluid - Templating made easy

Implement the ViewHelper!

The PHPDoc must exist (for validation)

All method parameters will be ViewHelper arguments

automatically

v4

Inspiring people toshareFluid - Templating made easy

Fluid Corev4v5

TemplateViewv5 View Helpers (Tags)v4

View Helpers (Tags)TemplateView

Fluid internals

Autocompletion

Balance

?????????????

inspiring people to share.

top related