[BUGFIX] Properly set format of StandaloneView
[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 TYPO3Fluid\Fluid\View\Exception\InvalidTemplateResourceException;
19
20 /**
21 * The main template view. Should be used as view if you want Fluid Templating
22 *
23 * @api
24 */
25 class TemplateView extends AbstractTemplateView
26 {
27 /**
28 * Init view
29 */
30 public function initializeView()
31 {
32 }
33
34 /**
35 * @param $templateName
36 */
37 public function setTemplate($templateName)
38 {
39 $this->baseRenderingContext->setControllerAction($templateName);
40 }
41
42 /**
43 * Sets the path and name of of the template file. Effectively overrides the
44 * dynamic resolving of a template file.
45 *
46 * @param string $templatePathAndFilename Template file path
47 * @api
48 */
49 public function setTemplatePathAndFilename($templatePathAndFilename)
50 {
51 $this->baseRenderingContext->getTemplatePaths()->setTemplatePathAndFilename($templatePathAndFilename);
52 }
53
54 /**
55 * Sets the path and name of the layout file. Overrides the dynamic resolving of the layout file.
56 *
57 * @param string $layoutPathAndFilename Path and filename of the layout file
58 * @api
59 */
60 public function setLayoutPathAndFilename($layoutPathAndFilename)
61 {
62 $this->baseRenderingContext->getTemplatePaths()->setLayoutPathAndFilename($layoutPathAndFilename);
63 }
64
65 /**
66 * Resolves the template root to be used inside other paths.
67 *
68 * @return array Path(s) to template root directory
69 */
70 public function getTemplateRootPaths()
71 {
72 return $this->baseRenderingContext->getTemplatePaths()->getTemplateRootPaths();
73 }
74
75 /**
76 * Set the root path(s) to the templates.
77 * If set, overrides the one determined from $this->templateRootPathPattern
78 *
79 * @param array $templateRootPaths Root path(s) to the templates. If set, overrides the one determined from $this->templateRootPathPattern
80 * @api
81 */
82 public function setTemplateRootPaths(array $templateRootPaths)
83 {
84 $this->baseRenderingContext->getTemplatePaths()->setTemplateRootPaths($templateRootPaths);
85 }
86
87 /**
88 * Set the root path(s) to the partials.
89 * If set, overrides the one determined from $this->partialRootPathPattern
90 *
91 * @param array $partialRootPaths Root paths to the partials. If set, overrides the one determined from $this->partialRootPathPattern
92 * @api
93 */
94 public function setPartialRootPaths(array $partialRootPaths)
95 {
96 $this->baseRenderingContext->getTemplatePaths()->setPartialRootPaths($partialRootPaths);
97 }
98
99 /**
100 * Set the root path(s) to the layouts.
101 * If set, overrides the one determined from $this->layoutRootPathPattern
102 *
103 * @param array $layoutRootPaths Root path to the layouts. If set, overrides the one determined from $this->layoutRootPathPattern
104 * @api
105 */
106 public function setLayoutRootPaths(array $layoutRootPaths)
107 {
108 $this->baseRenderingContext->getTemplatePaths()->setLayoutRootPaths($layoutRootPaths);
109 }
110
111 /**
112 * Checks whether a template can be resolved for the current request context.
113 *
114 * @param ControllerContext $controllerContext Controller context which is available inside the view
115 * @return bool
116 * @api
117 */
118 public function canRender(ControllerContext $controllerContext)
119 {
120 try {
121 $request = $controllerContext->getRequest();
122 $this->setControllerContext($controllerContext);
123 $this->baseRenderingContext->getTemplatePaths()->setFormat($request->getFormat());
124 $this->baseRenderingContext->getTemplatePaths()->getTemplateSource($request->getControllerName(), $request->getControllerActionName());
125 return true;
126 } catch (InvalidTemplateResourceException $e) {
127 return false;
128 }
129 }
130 }