Bug #60338
Changing view format does not affect partial format
Status: | Resolved | Start date: | 2014-07-15 | |
---|---|---|---|---|
Priority: | Must have | Due date: | ||
Assigned To: | Markus Klein | % Done: | 100% |
|
Category: | - | Spent time: | - | |
Target version: | next-patchlevel | |||
TYPO3 Version: | 6.2 | Is Regression: | No | |
PHP Version: | Sprint Focus: | Remote Sprint | ||
Complexity: |
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.
Related issues
Associated revisions
[BUGFIX] Respect format when rendering partial
The request format needs to be respected when rendering partials,
otherwise the same partial cannot be rendered in different formats
in the same request.
An example is rendering mails in plain text and HTML.
Resolves: #60338
Releases: master, 6.2
Change-Id: I118ee0a535d0f06391cd802c10d7c3c5129c2a2c
Reviewed-on: http://review.typo3.org/35475
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
[BUGFIX] Respect format when rendering partial
The request format needs to be respected when rendering partials,
otherwise the same partial cannot be rendered in different formats
in the same request.
An example is rendering mails in plain text and HTML.
Resolves: #60338
Releases: master, 6.2
Change-Id: I118ee0a535d0f06391cd802c10d7c3c5129c2a2c
Reviewed-on: http://review.typo3.org/40831
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
History
#1 Updated by Mathias Brodala about 1 year 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
.
#2 Updated by Markus Klein about 1 year ago
- Project changed from Fluid to Core
- Category deleted (
Fluid: View) - Status changed from New to Accepted
#3 Updated by Markus Klein about 1 year 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.
#4 Updated by Gerrit Code Review 8 months 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
#5 Updated by Markus Klein 4 months 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?
#6 Updated by Mathias Brodala 4 months 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?
#7 Updated by Markus Klein 4 months ago
Yes we reference a partial called "footer" in the mails which is present in .html and .txt format.
The output is correct.
#8 Updated by Mathias Brodala 4 months 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
.
#9 Updated by Markus Klein 4 months 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.
#10 Updated by Mathias Brodala 4 months 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.
#11 Updated by Markus Klein 4 months ago
We discussed that and concluded that it has to go into StandaloneView and FLUIDTEMPLATE will use it.
#12 Updated by Mathias Brodala 4 months 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?
#13 Updated by Markus Klein 4 months ago
I'm not aware of another ticket.
#14 Updated by Markus Klein 4 months 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.
#15 Updated by Markus Klein 4 months 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
#16 Updated by Mathias Brodala 4 months 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. ;-)
#17 Updated by Gerrit Code Review about 1 month 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
#18 Updated by Markus Klein about 1 month ago
- Assigned To set to Markus Klein
- Sprint Focus set to Remote Sprint
#19 Updated by Markus Klein about 1 month 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" />
#20 Updated by Gerrit Code Review about 1 month 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
#21 Updated by Gerrit Code Review about 1 month 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
#22 Updated by Mathias Brodala about 1 month ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset f55c7e0fc9ebb6330f2c0e0763845890d732089b.