• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Not a bug Template Bug: <xen:navigation> doesnt allow <xen:if> Tag

#1
I cannot use the xen:if tag inside the xen:navigation tag. This code produces an template error:

PHP:
<xen:navigation>
    <xen:if is="{category}">
        <xen:breadcrumb href="{$categoryLink}">{$category}</xen:breadcrumb>
    </xen:if>
    <xen:breadcrumb href="{$breadcrumbLink}">{$article.article_name}</xen:breadcrumb>
</xen:navigation>
Error:

Code:
Line 2: Invalid data found in navigation tag.
However using the same xen:if syntax after the xen:navigation tab doesnt result in this error.

PHP:
<xen:navigation>
    <xen:breadcrumb href="{$breadcrumbLink}">{$article.article_name}</xen:breadcrumb>
</xen:navigation>

    <xen:if is="{category}">
        {$category}
    </xen:if>
-> No Error.
 

xf_phantom

Well-known member
#2
You could use
Code:
<xen:if is="{category}">
         <xen:navigation>
                   <xen:breadcrumb href="{$categoryLink}">{$category}</xen:breadcrumb>
      </xen:navigation>
<xen:else />
           <xen:navigation>
                  <xen:breadcrumb href="{$breadcrumbLink}">{$article.article_name}  </xen:breadcrumb>
         </xen:navigation>
</xen:if>
 

xf_phantom

Well-known member
#4
You are absolutley right. But is there a reason why it doesnt work inside the navigation tab?
there are several tags, which doesn't allow other tags (or like in this case only the breadcrumb tag)


e.g. in XenForo_Template_Compiler_Tag_Navigation
you'll find that only breadcrumb is allowed
PHP:
    foreach ($children AS $child)
     {
       if ($compiler->isSegmentNamedTag($child, 'breadcrumb'))
       {
         if (isset($child['attributes']['source']))
         {
           $sourceVar = $compiler->compileVarRef($child['attributes']['source'], $options);
           $rawStatement->addStatement(
             '$__extraData[\'navigation\'] = XenForo_Template_Helper_Core::appendBreadCrumbs($__extraData[\'navigation\'], '
             . $sourceVar . ");\n"
           );
         }
         else
         {
           $parts = array();
           foreach ($child['attributes'] AS $name => $value)
           {
             $parts[] = "'" . $compiler->escapeSingleQuotedString($name) . "' => " . $compiler->compileAndCombineSegments($value, $options);
           }

           $parts[] = "'value' => " . $compiler->compileAndCombineSegments($child['children'], $options);

           $rawStatement->addStatement('$__extraData[\'navigation\'][] = array(' . implode(', ', $parts) . ");\n");
         }
       }
       else if (is_string($child) && trim($child) === '')
       {
         // whitespace -- ignore it
       }
       else
       {
         throw $compiler->getNewCompilerException(new XenForo_Phrase('invalid_data_found_in_navigation_tag'), $child);
       }
     }
 
#5
Thanks but I guess with that design concept i am not able to achieve what i want.

I have pages with or without a category. If they are in a category i want my breadcrumb like this:

Code:
addon->category->article
without category

Code:
addon->article
the point is that it seems that templates only allow one navigation tag. If I use the xen:if tag outside the xen:navigation scope I am only able to render one breadcrumb.

So to fit my needs my template would look like:

Code:
<xen:if is="{$category}">
         <xen:navigation>
                   <xen:breadcrumb href="{$categoryLink}">{$category}</xen:breadcrumb>
        </xen:navigation>
</xen:if>
         <xen:navigation>
                  <xen:breadcrumb href="{$breadcrumbLink}">{$article.article_name}  </xen:breadcrumb>
</xen:navigation>

but this way only one navigation tag gets rendered. Not both of them.
 
Last edited: