Bug #60338
closedChanging view format does not affect partial format
100%
Description
When using one view object to render a template in different formats (e.g. email in text and HTML), the template respects the requested format. However, partials are always rendered in the first rendered format. Example:
Content of templates/partials:
Content of Foo.txt
:
Hello <f:render partial="Bar"/>
Content of Partials/Bar.txt
:
World
Content of Foo.html
:
<p>Text</p> <f:render partial="Bar"/>
Content of Partials/Bar.html
:
<p>World</p>
1st invocation:
// Let $view be an instance of \TYPO3\CMS\Fluid\View\TemplateView $view->setFormat('txt'); $view->render('Foo');
Result:
Hello World
2nd invocation:
// $view is the same instance as above $view->setFormat('html'); $view->render('Foo');
Result:
<p>Hello</p> World
As you can see, the 2nd output was rendered using the txt-Partial.
This is due to the local partial identifier cache in AbstractTemplateView
which only considers the partial name, not the current request format. If that one is incorporated, separate cache entries for each partial formats are created.
Updated by Mathias Brodala over 10 years ago
The setFormat
call is not possible with the default TemplateView
of course. Imagine one would modify the current Request
object instead which also resides in the ControllerContext
.
Updated by Markus Klein over 10 years ago
- Project changed from 2559 to TYPO3 Core
- Category deleted (
Fluid: View) - Status changed from New to Accepted
Updated by Markus Klein over 10 years ago
- TYPO3 Version set to 6.2
- Is Regression set to No
Please report all Bugs to the Core project. Fluid and Extbase projects are legacy only.
Updated by Gerrit Code Review almost 10 years ago
- Status changed from Accepted to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/35475
Updated by Markus Klein over 9 years ago
We use it with StandaloneView like this and have no problems:
$view->setTemplateSource(self::getTemplate($templatePath . '.html', $languagePath)); $view->setFormat('html'); $mailContent['html'] = $view->render(); $view->setTemplateSource(self::getTemplate($templatePath . '.txt', $languagePath)); $view->setFormat('txt'); $mailContent['text'] = $view->render();
Can you figure out the difference to TemplateView here?
Updated by Mathias Brodala over 9 years ago
Markus Klein wrote:
We use it with StandaloneView like this and have no problems:
[...]
Does your template reference a partial which exists in txt and html format? Is that partial properly rendered depending on format?
Updated by Markus Klein over 9 years ago
Yes we reference a partial called "footer" in the mails which is present in .html and .txt format.
The output is correct.
Updated by Mathias Brodala over 9 years ago
The thing is that StandaloneView
does not support templateRootPaths
which we need to provide a default template with a list of optional overrides. That's why we cannot switch from TemplateView
.
Updated by Markus Klein over 9 years ago
StandaloneView will get templateRootPaths ;-) that has just been discussed.
But this actually does not matter here. The question is, why does this fail with TemplateView but work with StandaloneView?
Or is it something else that makes up the difference.
Updated by Mathias Brodala over 9 years ago
Markus Klein wrote:
StandaloneView will get templateRootPaths ;-) that has just been discussed.
AFAIS this is about the FLUIDTEMPLATE
content object, not the StandaloneView
: #66111
But this actually does not matter here. The question is, why does this fail with TemplateView but work with StandaloneView?
Or is it something else that makes up the difference.
Well, a huge difference is in createIdentifierForFile
but it's a bit hard to track down.
Updated by Markus Klein over 9 years ago
We discussed that and concluded that it has to go into StandaloneView and FLUIDTEMPLATE will use it.
Updated by Mathias Brodala over 9 years ago
Markus Klein wrote:
We discussed that and concluded that it has to go into StandaloneView and FLUIDTEMPLATE will use it.
Sounds great and would at least solve my issue at hand if I switch to StandaloneView
then.
Is this still tracked in the ticket I've linked or another one?
Updated by Markus Klein over 9 years ago
But it is no solution to switch everything to StandaloneView. Formats have to work for partials, no question!
So it would really be cool good to find out the difference.
Updated by Markus Klein over 9 years ago
Ah one more note: I only tested this on master, since my extension is CMS 7 only, no 6.2 support. So maybe the issue is only in 6.2
Updated by Mathias Brodala over 9 years ago
Markus Klein wrote:
But it is no solution to switch everything to StandaloneView. Formats have to work for partials, no question!
So it would really be cool good to find out the difference.
Yes of course. I just wanted to add the proper issue relation. ;-)
Updated by Gerrit Code Review over 9 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/35475
Updated by Markus Klein over 9 years ago
- Assignee set to Markus Klein
- Sprint Focus set to Remote Sprint
Updated by Markus Klein over 9 years ago
I can confirm the issue with StandaloneView as well!
A simple workaround though is to define the format explicitly in the txt-template.
Example¶
Foo.html
<f:render partial="Footer" />
Foo.txt
<f:render partial="Footer.txt" />
Updated by Gerrit Code Review over 9 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/35475
Updated by Gerrit Code Review over 9 years ago
Patch set 1 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/40831
Updated by Mathias Brodala over 9 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset f55c7e0fc9ebb6330f2c0e0763845890d732089b.