Bug #45735

Error when using If-Condition in Layout-Tag

Added by Alex no-lastname-given almost 9 years ago. Updated over 6 years ago.

Status:
Resolved
Priority:
Must have
Category:
Core
Target version:
-
Start date:
2013-02-22
Due date:
% Done:

100%

Estimated time:
Has patch:
No

Description

I use a condition for evaluating which layout to load:

<f:layout name="{f:if(condition: checkCondition, then: 'Layout1', else: 'Layout2')}"/>

On the first request (template is not cached) it works fine, but on the second requets (template is loaded from cache) following error is thrown:

#1: Notice: Undefined variable: self in /Data/Temporary/Development/Cache/Code/Fluid_TemplateCache/PACKAGE_CONTROLLER_action_ACTION_20bd4ce9d92ee470c3edcf16e49b6ebec6252766.php line 16 

This error can be fixed by adding a single line in store() of class TemplateCompiler (TYPO3.Fluid\Classes\TYPO3\Fluid\Core\Compiler\TemplateCompiler.php). The template code ($templateCode) have to be enhanced in the first line of getLayoutName() by

\$self = \$this;

To clarify, the final template code:

$templateCode = <<<EOD
%s {

public function getVariableContainer() {
    // TODO
    return new \TYPO3\Fluid\Core\ViewHelper\TemplateVariableContainer();
}
public function getLayoutName(\TYPO3\Fluid\Core\Rendering\RenderingContextInterface \$renderingContext) {
\$self = \$this;
%s
return %s;
}
public function hasLayout() {
return %s;
}

%s

}
EOD;

#1

Updated by Adrian Föder over 8 years ago

  • Status changed from New to Needs Feedback

alex, is this still present?

#2

Updated by Sebastian Düvel over 7 years ago

I have the same problem, so yes, it's still present.

#3

Updated by Bastian Waidelich over 7 years ago

  • Status changed from Needs Feedback to Accepted
  • Assignee set to Bastian Waidelich
  • Has patch changed from Yes to No
#4

Updated by Gerrit Code Review over 7 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master of project Packages/TYPO3.Fluid has been pushed to the review server.
It is available at https://review.typo3.org/31065

#5

Updated by Gerrit Code Review over 7 years ago

Patch set 2 for branch master of project Packages/TYPO3.Fluid has been pushed to the review server.
It is available at https://review.typo3.org/31065

#6

Updated by Gerrit Code Review over 7 years ago

Patch set 1 for branch 2.2 of project Packages/TYPO3.Fluid has been pushed to the review server.
It is available at https://review.typo3.org/31067

#7

Updated by Gerrit Code Review over 7 years ago

Patch set 1 for branch 2.1 of project Packages/TYPO3.Fluid has been pushed to the review server.
It is available at https://review.typo3.org/31068

#8

Updated by Bastian Waidelich over 7 years ago

  • Status changed from Under Review to Resolved
#9

Updated by Gerrit Code Review over 6 years ago

  • Status changed from Resolved to Under Review

Patch set 2 for branch 2.1 of project Packages/TYPO3.Fluid has been pushed to the review server.
It is available at http://review.typo3.org/31068

#10

Updated by Bastian Waidelich over 6 years ago

  • Status changed from Under Review to Resolved

Also available in: Atom PDF