Bug #45735

Error when using If-Condition in Layout-Tag

Added by Alex no-lastname-given over 2 years ago. Updated about 1 month ago.

Status:Resolved Start date:2013-02-22
Priority:Must have Due date:
Assigned To:Bastian Waidelich % Done:

100%

Category:Core
Target version:-
Has patch:No Affected Flow version:Flow 2.0.0 beta 1

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;

Associated revisions

Revision 4d167279
Added by Bastian Waidelich about 1 year ago

[BUGFIX] Support for ViewHelper usage within layout tags

Previously, when using ViewHelpers in the ``name`` argument of the
``<f:layout />`` tag, the TemplateCompiler threw an exception
``Notice: Undefined variable: self...`` when rendering the compiled
template.

This change fixes this by adding the respective initialization code
before the closure that makes use of ``$self``.

Change-Id: Ie45c92125a8a1f6b1fa0c5e4a5369486361c9c7c
Fixes: #45735
Releases: master, 2.2, 2.1

Revision b79dabb1
Added by Bastian Waidelich about 1 year ago

[BUGFIX] Support for ViewHelper usage within layout tags

Previously, when using ViewHelpers in the ``name`` argument of the
``<f:layout />`` tag, the TemplateCompiler threw an exception
``Notice: Undefined variable: self...`` when rendering the compiled
template.

This change fixes this by adding the respective initialization code
before the closure that makes use of ``$self``.

Change-Id: Ie45c92125a8a1f6b1fa0c5e4a5369486361c9c7c
Fixes: #45735
Releases: master, 2.2, 2.1

Revision 7a06d525
Added by Bastian Waidelich about 1 month ago

[BUGFIX] Support for ViewHelper usage within layout tags

Previously, when using ViewHelpers in the ``name`` argument of the
``<f:layout />`` tag, the TemplateCompiler threw an exception
``Notice: Undefined variable: self...`` when rendering the compiled
template.

This change fixes this by adding the respective initialization code
before the closure that makes use of ``$self``.

Change-Id: Ie45c92125a8a1f6b1fa0c5e4a5369486361c9c7c
Fixes: #45735
Releases: master, 2.2, 2.1

History

#1 Updated by Adrian Föder almost 2 years ago

  • Status changed from New to Needs Feedback

alex, is this still present?

#2 Updated by Sebastian Düvel about 1 year ago

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

#3 Updated by Bastian Waidelich about 1 year ago

  • Status changed from Needs Feedback to Accepted
  • Assigned To set to Bastian Waidelich
  • Has patch changed from Yes to No

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

  • Status changed from Under Review to Resolved

#9 Updated by Gerrit Code Review about 1 month 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 about 1 month ago

  • Status changed from Under Review to Resolved

Also available in: Atom PDF