1
votes

I wrote a viewhelper with renderChildren()... I get this error, which makes no sense to me: Templating tags not properly nested. Expected: Tx_Hplusinfo_ViewHelpers_RehaKatViewHelper; Actual: Tx_hplusinfo_ViewHelpers_RehaKatViewHelper

Here is the template part which leads to this message:

<f:if condition="{demand.pageId}=={settings.sucheRehaPid}">
  <h:rehaKat klinik="{entfernung.klinik}" demand="{demand}" as="kat">
    <td><f:if condition="{kat.isStationaer}">&#10003;</f:if></td>
    <td><f:if condition="{kat.isAmbulant}">&#10003;</f:if></td>
  </h:rehaKat>
</f:if>

This is the viewhelper render function:

/**
 *
 * @param Tx_Hplusinfo_Domain_Model_Klinik $klinik
 * @param Tx_Hplusinfo_Domain_Model_SearchDemand $demand
 * @param string $as Iteration variable
 * @return string
 */
public function render(Tx_Hplusinfo_Domain_Model_Klinik $klinik, Tx_Hplusinfo_Domain_Model_SearchDemand $demand, $as ) {
        $isAmbulant = false;
        $isStationaer = false;

        foreach($klinik->getReha() as $klinikreha) {
                foreach($demand->getRehas() as $demandreha) {
                       if($klinikreha->getReha()->getUid() == $demandreha) {
                                if(!$isStationaer)
                                        $isStationaer = $klinikreha->getIsStationaer();
                                if(!$isAmbulant)
                                        $isAmbulant = $klinikreha->getIsAmbulant();
                                break;
                        }
                }
                if ($isAmbulant && $isStationaer)
                        break;
        }
        $this->templateVariableContainer->add($as, array('isAmbulant'=>$isAmbulant, 'isStationaer'=>$isStationaer));
        return $this->renderChildren();
}
2

2 Answers

1
votes

Does this mean that closing tags are case sensitive, opening tags are not?

Since I like answers to be 100% complete I would like to add the explanation here. The reason for this is two parts: one, PHP class names are case insensitive (although class loaders may not be, depending on file system etc.) - and two, Fluid itself keeps track of the class name assigned to a ViewHelpers opening node that it matches the resolved class name of the closing node.

So what happens when a namespace declaration or ViewHelper reference is mistyped in terms of case is:

  • When a tag is self-closing, PHP is asked if the resolved class name exists and if PHP is able to load the class, it gets used. This will happen if the class was successfully loaded previously in the same request or if your class loader and file system combination allows loading class files with case insensitive paths.
  • However, when a tag is not self closing, Fluid keeps the ViewHelperNode that was created with the class name (which may have succeeded even though the class name is technically incorrect, given the conditions above) and when detecting the closing node that sits on the same hierarchy level as the opening node, Fluid will attempt to resolve the ViewHelper class name once more and then compare that 1:1 to the opening node's class name. That means Fluid may judge your class names to be incorrect even if PHP is technically able to load the class (because of the perfect storm of class loading and case sensitivity or because it was previously loaded with a correctly cased class name and then reused because class_exists is case insensitive on already loaded classes).

So combine the triggers above and you can see that using a closing tag does mean Fluid behaves differently compared to using inline notation or self closing tags, and you can see how PHP class loading combined with Fluid behavior can in some edge cases result in this type of error occurring.

0
votes

Finally, I found the issue: It was a lower/upper misspelling of the namespace:

Wrong: {namespace h=Tx_hplusinfo_ViewHelpers}

Right: {namespace h=Tx_Hplusinfo_ViewHelpers} (capital h)

The strange thing is that this misspelling was not an issue for the opening tag or any inline viewhelpers, e.g.

{h:myFormatter(inp:{xy})}

Does this mean that closing tags are case sensitive, opening tags are not?