TYPO3 / Fluid

Fluid template rendering engine - Standalone version
GNU Lesser General Public License v3.0
152 stars 93 forks source link

Rendering of empty template file returns null #407

Open s-diez opened 5 years ago

s-diez commented 5 years ago

If you render empty template files for example through TYPO3\CMS\Fluid\View\StandaloneView you get null as the return. This is kind of unexpected as the documentation of TYPO3Fluid\Fluid\View\AbstractTemplateView::render() has a return of type string. Furthermore if you do not expect this and try to cache the output in TYPO3\CMS\Core\Cache\Frontend\StringFrontend it will never be cached, as null can not be cached by it.

Especially because of the documentation and the interaction with the cache, I would consider this a bug.

derhansen commented 3 years ago

I would also say this is a bug. At least it leads to problem when you with with strict types and expect render() to return a string.

See: https://github.com/einpraegsam/powermail/pull/641

NamelessCoder commented 3 years ago

Agreed, but I think the right solution is to correct the return type annotation to string|null - it is nice to be able to tell if the template truly didn't cause any output at all, versus if it did render a template but the result was an empty string. Among other things this is used in f:render to determine if the default/fallback representation should be returned if for example a non-existing partial or section was rendered but optional=true was requested.