FluidTYPO3 / vhs

TYPO3 extension VHS: Fluid ViewHelpers
https://fluidtypo3.org
Other
189 stars 228 forks source link

BUG: v:render.template "is missing a valid request object." #1876

Closed MediKathi closed 10 months ago

MediKathi commented 1 year ago

I have checked that the bug exists in the dev-development branch Yes, vhs and flux

I have checked that there are no already open issues or recently closed issues about this bug Yesm found no matching issue

Describe the bug If I use v:render.template, Typo3 throws an error.

To Reproduce Steps to reproduce the behavior:

  1. Create a Emtpy Flux Page Layout.
  2. Have a Partial "Test"
  3. Have this inside your Partial:
    <f:link.page pageUid="1">Test</f:link.page>
  4. Try to use v:render.template on the partial
  5. See Error:
    
    (1/1) #1639819269 RuntimeException

The rendering context of ViewHelper f:link.page is missing a valid request object.



**Expected behavior**
v:render.template should work mostly like "f:render partial"

**Additional context**
Found the Issue while Trying to migrate from:
Typo3 v11 LTS
flux 9.7.2
vhs 6.1.3
To
Typo3 v12 LTS
flux dev
vhs dev
jensengelmann commented 11 months ago

The StandAloneView in TYPO3 12 does not create an Extbase Request anymore; see https://docs.typo3.org/c/typo3/cms-core/12.4/en-us/Changelog/12.0/Breaking-98377-FluidStandaloneViewDoesNotCreateAnExtbaseRequestAnymore.html and https://stackoverflow.com/questions/76473242/typo3-12-lts-fluid-the-rendering-context-of-viewhelper-furi-page-is-missing-a

For a quick workaround, you can set the request manually in the render function right before the return statement: $view->setRequest($this->renderingContext->getRequest());

Maybe there might be a global solution by somehow adding the request in the getPreparedView() function in the AbstractRenderViewHelper.

NamelessCoder commented 10 months ago

v:render.template does not (and should not) create an internal Extbase request - it follows a standalone view and lets the TYPO3 core decide how to handle those. This means that any controller-specific ViewHelpers like f:link.action simply does not work within that context.

The odd thing is that TYPO3 decided that the exception messages for those controller-specific ViewHelpers should throw an exception clearly stating that they depend on a controller/request context - but the error message for f:link.page and f:uri.page for some reason only says that they need a Request, not that they do not work outside a controller/request context. And this reductive error message is what leads to the confusion.

To be clear: the f:link.page and every other controller/request specific ViewHelper will never be made to work inside a template rendered by v:render.template or other standalone template rendering methods. It is the wrong context for such ViewHelpers.

You have two methods that would solve the problem:

This means that the expectation:

v:render.template should work mostly like "f:render partial"

Is somewhat incorrect. It's true that it should mostly work like f:render with partial argument, but one of the (key) ways it differs from f:render is precisely that it creates a new, non-controller-related context: in short, it's identical to using a FLUIDTEMPLATE TypoScript object. This is also mentioned in the documentation for v:render.template (although knowing that this is the cause is a bit hard, given the reductive error message from f:link.page).