[TASK] Merge submodule linkvalidator into core
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / AliasViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 /**
15 * Declares new variables which are aliases of other variables.
16 * Takes a "map"-Parameter which is an associative array which defines the shorthand mapping.
17 *
18 * The variables are only declared inside the <f:alias>...</f:alias>-tag. After the
19 * closing tag, all declared variables are removed again.
20 *
21 * = Examples =
22 *
23 * <code title="Single alias">
24 * <f:alias map="{x: 'foo'}">{x}</f:alias>
25 * </code>
26 * <output>
27 * foo
28 * </output>
29 *
30 * <code title="Multiple mappings">
31 * <f:alias map="{x: foo.bar.baz, y: foo.bar.baz.name}">
32 * {x.name} or {y}
33 * </f:alias>
34 * </code>
35 * <output>
36 * [name] or [name]
37 * depending on {foo.bar.baz}
38 * </output>
39 *
40 * @api
41 */
42 class AliasViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
43
44 /**
45 *
46 * @param array $map array that specifies which variables should be mapped to which alias
47 * @return string Rendered string
48 * @api
49 */
50 public function render(array $map) {
51 foreach ($map as $aliasName => $value) {
52 $this->templateVariableContainer->add($aliasName, $value);
53 }
54 $output = $this->renderChildren();
55 foreach ($map as $aliasName => $value) {
56 $this->templateVariableContainer->remove($aliasName);
57 }
58 return $output;
59 }
60 }
61
62 ?>