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.
25. Goals of Fluid
Simple, elegant template engine
support for the template writer in many ways
simple and clean extensibility
different output formats possible
Inspiring people to
Fluid - Templating made easy share
41. Fluid for professionals
Forms
/**
* Displays a form for creating a new blog
*
* @param F3BlogDomainModelBlog $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(F3BlogDomainModelBlog $newBlog = NULL) {
$this->view->assign('newBlog', $newBlog);
}
/**
* Creates a new blog
*
* @param F3BlogDomainModelBlog $newBlog A fresh Blog object which has not yet been added to the repository
* @return void
*/
public function createAction(F3BlogDomainModelBlog $newBlog) {
$this->blogRepository->add($newBlog);
$this->pushFlashMessage('Your new blog was created.');
$this->redirect('index');
}
Inspiring people to
Fluid - Templating made easy share
44. Fluid for professionals
Forms
/**
* Displays a form for creating a new blog
*
* @param F3BlogDomainModelBlog $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(F3BlogDomainModelBlog $newBlog = NULL) {
$this->view->assign('newBlog', $newBlog);
}
/**
* Creates a new blog
*
* @param F3BlogDomainModelBlog $newBlog A fresh Blog object which has not yet been added to the repository
* @return void
*/
public function createAction(F3BlogDomainModelBlog $newBlog) {
$this->blogRepository->add($newBlog);
$this->pushFlashMessage('Your new blog was created.');
$this->redirect('index');
}
Inspiring people to
Fluid - Templating made easy share
45. Fluid for professionals
Forms
/**
* Displays a form for creating a new blog
*
* @param F3BlogDomainModelBlog $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(F3BlogDomainModelBlog $newBlog = NULL) {
$this->view->assign('newBlog', $newBlog);
}
/**
* Creates a new blog
*
* @param F3BlogDomainModelBlog $newBlog A fresh Blog object which has not yet been added to the repository
* @return void
*/
public function createAction(F3BlogDomainModelBlog $newBlog) {
$this->blogRepository->add($newBlog);
$this->pushFlashMessage('Your new blog was created.');
$this->redirect('index');
}
Inspiring people to
Fluid - Templating made easy share
46.
47. Layouts
Inspiring people to
Fluid - Templating made easy share
49. Fluid for professionals
Layouts
<f:layout name="master" />
<f:section name="main">
<h1> My content</h1>
</f:section>
Inspiring people to
Fluid - Templating made easy share
52. Custom ViewHelpers
Inspiring people to
Fluid - Templating made easy share
53. Custom ViewHelpers
v4 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“ />
Inspiring people to
Fluid - Templating made easy share
54. Custom ViewHelpers
v4 Task: Gravatar ViewHelper
Expected usage:
{namespace blog=Tx_Blog_ViewHelpers}
<blog:gravatar email=“sebastian@typo3.org“ />
Inspiring people to
Fluid - Templating made easy share
55. Custom ViewHelpers
v4 1. Create a ViewHelper skeleton
class Tx_Blog_ViewHelpers_GravatarViewHelper
extends Tx_Fluid_Core_AbstractViewHelper {
public function render() {
return ‘Hello World‘;
}
}
Inspiring people to
Fluid - Templating made easy share
56. Custom ViewHelpers
v4 Implement the ViewHelper!
The PHPDoc must
/** exist (for validation)
* @param string $email The email to render as gravatar
*/
public function render($email) {
return ‘http://www.gravatar.com/gravatar/‘ . md5($email);
}
All method parameters will be
ViewHelper arguments
automatically
Inspiring people to
Fluid - Templating made easy share
57.
58. Fluid internals
TemplateView View Helpers (Tags)
v5 v4 TemplateView View Helpers (Tags)
v5 v4 Fluid Core
Inspiring people to
Fluid - Templating made easy share