Bug #38369

Resource ViewHelpers should not fall back to request package

Added by Bastian Waidelich almost 9 years ago. Updated almost 9 years ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
View
Target version:
-
Start date:
2012-06-25
Due date:
% Done:

0%

Estimated time:
Has patch:
No

Description

Currently the f:uri.resource ViewHelper uses the package key of the current request to determine the absolute resource path, if no package is specified.

The resource interceptor that replaces links to assets by the resource viewhelper, so:

<link rel="stylesheet" href="../../../Public/Stylesheets/SomeFile.css" media="all" />


is (internally) converted into
<link rel="stylesheet" href="{f:uri.resource(resource: 'Stylesheets/SomeFile.css')}" media="all" />

So the resource ViewHelper uses the current package key to resolve the path to: Current/Package/Resources/Public/Stylesheets/SomeFile.css.
While this mostly works for FLOW3, in Phoenix the current package is usually TYPO3.TYPO3 and resources are located in some site package.

Therefore the TypoScript Fluid renderer sets the requests package key from the Fluid template path:

if (strpos($templatePath, 'resource://') === 0) {
    $tmp = substr($templatePath, 11);
    $tmp2 = explode('/', $tmp);

    $fluidTemplate->getRequest()->setControllerPackageKey(array_shift(($tmp2)));
}

This has the side effect, that all links in the Fluid template now point to the site package instead of the FrontendNode controller of the TYPO3 package!

I didn't set the category to ViewHelpers because IMO this should be fixed in the view: We probably need something like resourcesPackage or similar that should be used by the resource ViewHelper instead of the requests package key.

#1

Updated by Bastian Waidelich almost 9 years ago

Bastian Waidelich wrote:

I didn't set the category to ViewHelpers because IMO this
should be fixed in the view

BTW: This would be a good chance to clean up the code in the FluidRenderer (:

if (strpos($templatePath, 'resource://') === 0) {
    $resourcePathWithoutProtocol = substr($templatePath, 11);
    $resourcePathSegments = explode('/', $resourcePathWithoutProtocol);
    $resourcePackageKey = array_shift($resourcePathSegments);
    $fluidTemplate->setDefaultResourcePackage($resourcePackageKey);
}

#2

Updated by Karsten Dambekalns almost 9 years ago

IMHO the description is misleading, as this is not an issue with the RVH, but rather a "usage problem", in that for Phoenix there is a difference between "current and current" ;).

Also available in: Atom PDF