Project

General

Profile

Actions

Bug #65340

closed

Show error message when FLUIDTEMPLATE file path is incorrect

Added by Olle Haerstedt over 9 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Should have
Category:
TypoScript
Target version:
Start date:
2015-02-25
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
medium
Is Regression:
No
Sprint Focus:

Description

Wasted an hour on a problem which was a simple typo in my file path. Would be good if there were an error message if this happened. Example TS:

tt_content.cat_button = FLUIDTEMPLATE
tt_content.cat_button {
    template = FILE
    template.file = EXT:so_product/Resources/Private/Templates/ContentELements/CategoryButton.html
    layoutRootPath = EXT:so_product/Resources/Private/Layouts/
}

Typo with `L` instead of `l` in `ContentELements`.

Suggestion for error message: `No such file or directory found`.

Actions #1

Updated by Markus Klein over 9 years ago

  • Target version changed from 7.0 to 7.2 (Frontend)

What did you get? No error message at all?
Did you take a look at the messages displayed in Admin Panel?

Actions #2

Updated by Olle Haerstedt over 9 years ago

  • Target version changed from 7.2 (Frontend) to 7.0

No error message at all. Confirmed in 6.2.9 and 7.2.

I think I've found the error.

This function is from FluidTemplateContentObject.php, where $templateSource will evaluate to empty string if not found.

    /**
     * Set template
     *
     * @param array $conf With possibly set file resource
     * @return void
     * @throws \InvalidArgumentException
     */
    protected function setTemplate(array $conf) {
        // Fetch the Fluid template
        if (!empty($conf['template']) && !empty($conf['template.'])) {
            $templateSource = $this->cObj->cObjGetSingle($conf['template'], $conf['template.']);
            // $templateSource is empty string, should be NULL?
            $this->view->setTemplateSource($templateSource);
        } else {
            $file = isset($conf['file.']) ? $this->cObj->stdWrap($conf['file'], $conf['file.']) : $conf['file'];
            /** @var $templateService \TYPO3\CMS\Core\TypoScript\TemplateService */
            $templateService = $GLOBALS['TSFE']->tmpl;
            $templatePathAndFilename = $templateService->getFileName($file);
            $this->view->setTemplatePathAndFilename(PATH_site . $templatePathAndFilename);
        }
    }

But here in StandaloneView.php, $templateSource must be NULL to throw an error:

    /**
     * Returns the Fluid template source code
     *
     * @param string $actionName Name of the action. This argument is not used in this view!
     * @return string Fluid template source
     * @throws InvalidTemplateResourceException
     */
    protected function getTemplateSource($actionName = NULL) {
        if ($this->templateSource === NULL && $this->templatePathAndFilename === NULL) {
            throw new InvalidTemplateResourceException('No template has been specified. Use either setTemplateSource() or setTemplatePathAndFilename().', 1288085266);
        }
        if ($this->templateSource === NULL) {    // Also check for empty string here?
            if (!is_file($this->templatePathAndFilename)) {
                throw new InvalidTemplateResourceException('Template could not be found at "' . $this->templatePathAndFilename . '".', 1288087061);
            }
            $this->templateSource = file_get_contents($this->templatePathAndFilename);
        }
        return $this->templateSource;
    }

Additionally, one could check for errors directly in setTemplate(), to fail as early as possible.

Actions #3

Updated by Olle Haerstedt over 9 years ago

  • Target version changed from 7.0 to 7.2 (Frontend)
Actions #4

Updated by Gerrit Code Review over 9 years ago

  • Status changed from New 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/37273

Actions #5

Updated by Gerrit Code Review over 9 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/37273

Actions #6

Updated by Benni Mack over 9 years ago

  • Target version changed from 7.2 (Frontend) to 7.4 (Backend)
Actions #7

Updated by Gerrit Code Review over 9 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/37273

Actions #8

Updated by Susanne Moog over 9 years ago

  • Target version changed from 7.4 (Backend) to 7.5
Actions #9

Updated by Benni Mack about 9 years ago

  • Target version changed from 7.5 to 7 LTS
Actions #10

Updated by Gerrit Code Review about 9 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/37273

Actions #11

Updated by Gerrit Code Review about 7 years ago

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

Actions #12

Updated by Gerrit Code Review about 7 years ago

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

Actions #13

Updated by Georg Ringer about 7 years ago

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

Updated by Riccardo De Contardi about 7 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF