diff --git a/09-templating.md b/09-templating.md index 68b895c..f485a09 100644 --- a/09-templating.md +++ b/09-templating.md @@ -8,7 +8,7 @@ A good quick read on this is [ircmaxell on templating](http://blog.ircmaxell.com For this tutorial we will use a PHP implementation of [Mustache](https://github.com/bobthecow/mustache.php). So install that package before you continue. -Other well known alternatives would be [Twig](http://twig.sensiolabs.org/) or [Smarty](http://www.smarty.net/), but they are both pretty bloated and offer too much functionality for just a template engine. +Another well known alternative would be [Twig](http://twig.sensiolabs.org/). Now please go and have a look at the source code of the [engine class](https://github.com/bobthecow/mustache.php/blob/master/src/Mustache/Engine.php). As you can see, the class does not implement an interface. diff --git a/11-page-menu.md b/11-page-menu.md index 6c1f43e..990496b 100644 --- a/11-page-menu.md +++ b/11-page-menu.md @@ -6,5 +6,26 @@ Now we have some sweet dynamic pages. But nobody can find them. Let's fix that now. In this chapter we will create a menu with links to all our pages. +For a start we will just send a hardcoded array to the template. Go to you `Homepage` controller and change your `$data` array to this: + +```php +$data = [ + 'name' => $this->request->getParameter('name', 'stranger'), + 'menuItems' => ['href' => '/', 'text' => 'Homepage'], +]; +``` + +Now add the following at the top of your `Homepage.mustache` file: + +``` +{{#menuItems}} + {{ text }}
+{{/menuItems}} +``` + +Now if you navigate to your homepage, you should see a link at the top. + +So far so good. But now we realize that we want to reuse this code snippet on every page. We could create a separate file and include it every time, but there is a better solution. + [<< previous](10-dynamic-pages.md) \ No newline at end of file