1
|
<?php
|
2
|
|
3
|
/* *
|
4
|
* This script is part of the TYPO3 project - inspiring people to share! *
|
5
|
* *
|
6
|
* TYPO3 is free software; you can redistribute it and/or modify it under *
|
7
|
* the terms of the GNU General Public License version 2 as published by *
|
8
|
* the Free Software Foundation. *
|
9
|
* *
|
10
|
* This script is distributed in the hope that it will be useful, but *
|
11
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
|
12
|
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
|
13
|
* Public License for more details. *
|
14
|
* */
|
15
|
|
16
|
/**
|
17
|
* A view helper for setting the document title in the <title> tag.
|
18
|
*
|
19
|
* = Examples =
|
20
|
*
|
21
|
* <page.title mode="prepend" glue=" - ">{blog.name}</page.title>
|
22
|
*
|
23
|
* <page.title mode="replace">Something here</page.title>
|
24
|
*
|
25
|
* <h1><page.title mode="append" glue=" | " display="render">Title</page.title></h1>
|
26
|
*
|
27
|
* @package Fluid
|
28
|
* @subpackage ViewHelpers
|
29
|
* @version $Id$
|
30
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
|
31
|
* @scope prototype
|
32
|
*/
|
33
|
class Tx_Fluid_ViewHelpers_Page_TitleViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
|
34
|
|
35
|
/**
|
36
|
* @param string $mode Method for adding the new title to the existing one.
|
37
|
* @param string $glue Glue the new title to the old title with this string.
|
38
|
* @param string $display If render, this tag displays it's children. By default it doesn't display anything.
|
39
|
* @return string Rendered content or blank depending on display mode.
|
40
|
* @author Nathan Lenz <nathan.lenz@organicvalley.coop>
|
41
|
*/
|
42
|
public function render($mode = 'replace', $glue = ' - ', $display = 'none') {
|
43
|
|
44
|
$renderedContent = $this->renderChildren();
|
45
|
|
46
|
$existingTitle = $GLOBALS['TSFE']->page['title'];
|
47
|
|
48
|
if ($mode === 'prepend' && !empty($existingTitle)) {
|
49
|
$newTitle = $renderedContent.$glue.$existingTitle;
|
50
|
} else if ($mode === 'append' && !empty($existingTitle)) {
|
51
|
$newTitle = $existingTitle.$glue.$renderedContent;
|
52
|
} else {
|
53
|
$newTitle = $renderedContent;
|
54
|
}
|
55
|
|
56
|
$GLOBALS['TSFE']->page['title'] = $newTitle;
|
57
|
|
58
|
if ($display === 'render') {
|
59
|
return $renderedContent;
|
60
|
} else {
|
61
|
return '';
|
62
|
}
|
63
|
}
|
64
|
}
|
65
|
?>
|