187c01b40240dd730f808d70be7ed336b81d02f8
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / View / TemplateView.php
1 <?php
2 namespace TYPO3\CMS\Fluid\View;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext;
18 use TYPO3\CMS\Fluid\Fluid;
19 use TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException;
20
21 /**
22 * The main template view. Should be used as view if you want Fluid Templating
23 *
24 * @api
25 */
26 class TemplateView extends AbstractTemplateView
27 {
28 /**
29 * Init view
30 */
31 public function initializeView()
32 {
33 }
34
35 /**
36 * @param $templateName
37 */
38 public function setTemplate($templateName)
39 {
40 $this->baseRenderingContext->setControllerAction($templateName);
41 }
42
43 /**
44 * Sets the path and name of of the template file. Effectively overrides the
45 * dynamic resolving of a template file.
46 *
47 * @param string $templatePathAndFilename Template file path
48 * @api
49 */
50 public function setTemplatePathAndFilename($templatePathAndFilename)
51 {
52 $this->baseRenderingContext->getTemplatePaths()->setTemplatePathAndFilename($templatePathAndFilename);
53 }
54
55 /**
56 * Sets the path and name of the layout file. Overrides the dynamic resolving of the layout file.
57 *
58 * @param string $layoutPathAndFilename Path and filename of the layout file
59 * @api
60 */
61 public function setLayoutPathAndFilename($layoutPathAndFilename)
62 {
63 $this->baseRenderingContext->getTemplatePaths()->setLayoutPathAndFilename($layoutPathAndFilename);
64 }
65
66 /**
67 * Resolves the template root to be used inside other paths.
68 *
69 * @return array Path(s) to template root directory
70 */
71 public function getTemplateRootPaths()
72 {
73 return $this->baseRenderingContext->getTemplatePaths()->getTemplateRootPaths();
74 }
75
76 /**
77 * Set the root path(s) to the templates.
78 * If set, overrides the one determined from $this->templateRootPathPattern
79 *
80 * @param array $templateRootPaths Root path(s) to the templates. If set, overrides the one determined from $this->templateRootPathPattern
81 * @api
82 */
83 public function setTemplateRootPaths(array $templateRootPaths)
84 {
85 $this->baseRenderingContext->getTemplatePaths()->setTemplateRootPaths($templateRootPaths);
86 }
87
88 /**
89 * Set the root path(s) to the partials.
90 * If set, overrides the one determined from $this->partialRootPathPattern
91 *
92 * @param array $partialRootPaths Root paths to the partials. If set, overrides the one determined from $this->partialRootPathPattern
93 * @api
94 */
95 public function setPartialRootPaths(array $partialRootPaths)
96 {
97 $this->baseRenderingContext->getTemplatePaths()->setPartialRootPaths($partialRootPaths);
98 }
99
100 /**
101 * Set the root path(s) to the layouts.
102 * If set, overrides the one determined from $this->layoutRootPathPattern
103 *
104 * @param array $layoutRootPaths Root path to the layouts. If set, overrides the one determined from $this->layoutRootPathPattern
105 * @api
106 */
107 public function setLayoutRootPaths(array $layoutRootPaths)
108 {
109 $this->baseRenderingContext->getTemplatePaths()->setLayoutRootPaths($layoutRootPaths);
110 }
111
112 /**
113 * Checks whether a template can be resolved for the current request context.
114 *
115 * @param ControllerContext $controllerContext Controller context which is available inside the view
116 * @return bool
117 * @api
118 */
119 public function canRender(ControllerContext $controllerContext)
120 {
121 try {
122 $request = $controllerContext->getRequest();
123 $this->setControllerContext($controllerContext);
124 $this->baseRenderingContext->getTemplatePaths()->setFormat($request->getFormat());
125 $this->baseRenderingContext->getTemplatePaths()->getTemplateSource($request->getControllerName(), $request->getControllerActionName());
126 return true;
127 } catch (InvalidTemplateResourceException $e) {
128 return false;
129 }
130 }
131 }