Question

I'm working on a new extension and my model has the attribute 'type' which can get different strings from the TCA form. Strings only! The name of the partial that my template should load is inside the 'type' attribute from my model. So here comes my problem. Since TYPO3 4.7.x the .html file names for fluid have to start with an uppercase letter. Inside the 'type' attribute the name of the partial that should be loaded is always lowercase. For that, I wrote a simple view helper that contains only this method:

public function render($string) {

    return ucfirst($string);
}

Inside my template I tried to use this view helper for the path to the partial:

{namespace vh=Tx_MyExtension_ViewHelpers}
<f:for each="{obj.subObjects}" as="sub">
    <f:render partial="OtherObject/{vh:String.UpperFirstCharacter(string:'{sub.type}')}" arguments="{sub:sub}" />
</f:for>

If I try to load this in the fontend, nothing from my extension will be rendered and there are no error messages anywhere. The problem depends on my view helper, 'cause even if I try to load only this:

{vh:String.UpperFirstCharacter(string:'test')}
{vh:String.UpperFirstCharacter(string:'{sub.type}')}

There is nothing comming back. If I only output {sub.type} it shows me the string that I want, but in lowercase.

Était-ce utile?

La solution 2

So I found the issue. Fluid can't handle namespaces. So first my ViewHelper looked like this:

<php
namespace TYPO3\MyExtension\ViewHelpers\String;
class UpperFirstCharacterViewHelper ...

Now I changed the name of my class and removed the namespace:

<php
class Tx_MyExtension_ViewHelpers_String_UpperFirstCharacterViewHelper ...

This is how it works. At the moment I work with TYPO3 6.1.6. Thank you anyway lorenz for your help!

EDIT:

I went fully retarded! Fluid CAN handle namespaces. I just had to set the namespace the right way. That's how you set the namespace inside the template:

{namespace vh=TYPO3\MyExtension\ViewHelpers}

On top of this comment you can see how my ViewHelper looks like with a namespace.

Autres conseils

Obviously your problem is that you're ViewHelper doesn't do what you want it to do.

First of all, ViewHelper names are to be written in lowerCamelCase.

Second, you don't need to place sub.type in curly braces:

This syntax...

{vh:string.upperFirstCharacter(string:sub.type)}

... should be sufficient.

Fluid will then look for a ViewHelper named

Tx_MyExtension_ViewHelpers_String_UpperFirstCharacter

or namespaced

\My\Extension\ViewHelpers\String\UpperFirstCharacter

Please check that this is the case.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top