Bug #60338

Changing view format does not affect partial format

Added by Mathias Brodala about 5 years ago. Updated 12 months ago.

Status:
Closed
Priority:
Must have
Assignee:
Category:
-
Target version:
Start date:
2014-07-15
Due date:
% Done:

100%

TYPO3 Version:
6.2
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:
Remote Sprint

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

Related to TYPO3 Core - Feature #66111: Add TemplateRootPaths support to cObject FLUIDTEMPLATE Closed 2015-03-28

Associated revisions

Revision f55c7e0f (diff)
Added by Mathias Brodala about 4 years ago

[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 <>
Tested-by: Markus Klein <>
Reviewed-by: Andreas Fernandez <>
Tested-by: Andreas Fernandez <>

Revision 78093743 (diff)
Added by Mathias Brodala about 4 years ago

[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 <>
Tested-by: Andreas Fernandez <>

History

#1 Updated by Mathias Brodala about 5 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.

#2 Updated by Markus Klein about 5 years ago

  • Project changed from Fluid to TYPO3 Core
  • Category deleted (Fluid: View)
  • Status changed from New to Accepted

#3 Updated by Markus Klein about 5 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.

#4 Updated by Gerrit Code Review almost 5 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

#5 Updated by Markus Klein over 4 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?

#6 Updated by Mathias Brodala over 4 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?

#7 Updated by Markus Klein over 4 years 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 over 4 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.

#9 Updated by Markus Klein over 4 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.

#10 Updated by Mathias Brodala over 4 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.

#11 Updated by Markus Klein over 4 years ago

We discussed that and concluded that it has to go into StandaloneView and FLUIDTEMPLATE will use it.

#12 Updated by Mathias Brodala over 4 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?

#13 Updated by Markus Klein over 4 years ago

I'm not aware of another ticket.

#14 Updated by Markus Klein over 4 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.

#15 Updated by Markus Klein over 4 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

#16 Updated by Mathias Brodala over 4 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. ;-)

#17 Updated by Gerrit Code Review over 4 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

#18 Updated by Markus Klein about 4 years ago

  • Assignee set to Markus Klein
  • Sprint Focus set to Remote Sprint

#19 Updated by Markus Klein about 4 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" />

#20 Updated by Gerrit Code Review about 4 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

#21 Updated by Gerrit Code Review about 4 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

#22 Updated by Mathias Brodala about 4 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#23 Updated by Benni Mack 12 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF