@@ -39,11 +39,11 @@ We'll use the `<title>` and `<meta name="description">` tags as an example. The
39
39
<html>
40
40
<head>
41
41
42
- <!-- The title tag shows the title of our site and the title of the current page -->
43
- <title><?= $site->title() ?> | <?= $page->title() ?></title>
44
-
45
- <!-- The meta description shows an excerpt of the main text -->
46
- <meta name="description" content="<?= $page->text()->excerpt(120) ?>">
42
+ <!-- The title tag shows the title of our site and the title of the current page -->
43
+ <title><?= $site->title() ?> | <?= $page->title() ?></title>
44
+
45
+ <!-- The meta description shows an excerpt of the main text -->
46
+ <meta name="description" content="<?= $page->text()->excerpt(120) ?>">
47
47
</head>
48
48
```
49
49
@@ -54,11 +54,11 @@ That's a perfectly fine and reasonable solution. But what if we want to show a s
54
54
<html>
55
55
<head>
56
56
57
- <!-- The title tag shows the title of our site and the title of the current page -->
58
- <title><?php e($page->isHomePage() , $site->title() . "|" . $site->tagline() , $site->title() . "|" . $page->title()) ?></title>
59
-
60
- <!-- The meta description shows an excerpt of the main text -->
61
- <meta name="description" content="<?= $page->text()->excerpt(120) ?>">
57
+ <!-- The title tag shows the title of our site and the title of the current page -->
58
+ <title><?php e($page->isHomePage() , $site->title() . "|" . $site->tagline() , $site->title() . "|" . $page->title()) ?></title>
59
+
60
+ <!-- The meta description shows an excerpt of the main text -->
61
+ <meta name="description" content="<?= $page->text()->excerpt(120) ?>">
62
62
63
63
</head>
64
64
```
@@ -75,13 +75,13 @@ The first thing we need to do is set up our default controller. To do that we'll
75
75
<?php
76
76
77
77
return function ($page, $pages, $site, $kirby) {
78
-
79
- # Fetch and store the content for the title tag and the meta description
80
- $titleTag = $site->title() . " | " . $page->title();
81
- $metaDescription = $page->text()->excerpt(120);
82
-
83
- # Return an array containing the data that we want to pass to the template
84
- return compact('titleTag' , 'metaDescription');
78
+
79
+ # Fetch and store the content for the title tag and the meta description
80
+ $titleTag = $site->title() . " | " . $page->title();
81
+ $metaDescription = $page->text()->excerpt(120);
82
+
83
+ # Return an array containing the data that we want to pass to the template
84
+ return compact('titleTag' , 'metaDescription');
85
85
86
86
};
87
87
```
@@ -92,12 +92,12 @@ Now that the logic to fetch the correct data has been moved inside the controlle
92
92
<!DOCTYPE html>
93
93
<html>
94
94
<head>
95
-
96
- <!-- The title tag we show the title of our site and the title of the current page -->
97
- <title><?= $titleTag ?></title>
98
95
99
- <!-- The meta description shows an excerpt of the main text -->
100
- <meta name="description" content="<?= $metaDescription ?>">
96
+ <!-- The title tag we show the title of our site and the title of the current page -->
97
+ <title><?= $titleTag ?></title>
98
+
99
+ <!-- The meta description shows an excerpt of the main text -->
100
+ <meta name="description" content="<?= $metaDescription ?>">
101
101
102
102
</head>
103
103
<body>
@@ -109,12 +109,12 @@ Excellent, this is already looking a lot cleaner. Now we need to implement the d
109
109
<?php
110
110
111
111
return function ($page, $pages, $site, $kirby) {
112
-
112
+
113
113
# Store the content for the different title tag
114
- $titleTag = $site->title() . " | " . $site->tagline();
115
-
114
+ $titleTag = $site->title() . " | " . $site->tagline();
115
+
116
116
# Return the array containing the data that we want to pass to the template
117
- return compact('titleTag');
117
+ return compact('titleTag');
118
118
119
119
};
120
120
```
@@ -164,15 +164,15 @@ The final `home.php` controller will look like this:
164
164
<?php
165
165
166
166
return function ($page, $pages, $site, $kirby) {
167
-
167
+
168
168
# Grab the data from the default controller
169
- $shared = $kirby->controller('site' , compact('page', 'pages', 'site', 'kirby'));
169
+ $shared = $kirby->controller('site' , compact('page', 'pages', 'site', 'kirby'));
170
170
171
171
# Fetch and store the content for the different title tag
172
- $titleTag = $site->title() . " | " . $site->tagline();
173
-
172
+ $titleTag = $site->title() . " | " . $site->tagline();
173
+
174
174
# Return the array containing the data that we want to pass to the template
175
- return A::merge($shared , compact('titleTag'));
175
+ return A::merge($shared , compact('titleTag'));
176
176
177
177
};
178
178
```
@@ -201,15 +201,15 @@ To do that you need to pass the correct controller name to the `controller()` fu
201
201
<?php
202
202
203
203
return function ($page, $pages, $site, $kirby) {
204
-
204
+
205
205
# Grab the data from the post.php controller
206
- $post = $kirby->controller('post' , compact('page', 'pages', 'site', 'kirby'));
206
+ $post = $kirby->controller('post' , compact('page', 'pages', 'site', 'kirby'));
207
207
208
208
# Custom content for the video post
209
- $video = $page->videourl();
210
-
209
+ $video = $page->videourl();
210
+
211
211
# Return the array containing the data that we want to pass to the template
212
- return A::merge($post , compact('video'));
212
+ return A::merge($post , compact('video'));
213
213
214
214
};
215
215
```
0 commit comments