As designed Templace conditional contentcheck not working inside a datalist when surrounding datarows

XFA

Well-known member
Affected version
Beta 4
Apparently, if the xf:contentcheck part of a content checking conditional is inside an xf:datalist, it doesn't work.
The compiler outputs a "Tag must be a valid conditional using an is attribute or content checking".

I used that because I don't want the datalist to show if there is no datarows knowing that my datalist always has at least a datarow (header row) and I don't know if there will be items as they are picked from a list based on a given condition.

I don't see any reason why you couldn't do that.

Clément
 
Content checking is specifically for preventing standard HTML output. Thus, in the tree structure of the compiler, the <xf:contentcheck> element must be a direct child of the <xf:if>. In other words, there can be no other <xf:...> elements between them.

The message could potentially be improved here, but otherwise, this is generally expected. You may need to take a slightly different approach (such as use <xf:set> to check if there's any output).
 
@Mike,

Ah ok well I figured you would say it's as designed.

Could you elaborate a bit about the xf:set ?

I tried using it yesterday and I am unsure of the behavior.
Did that:
HTML:
<xf:set var="$show">0</xf:set>
<xf:if is="a condition">
    <xf:set var="$show">1</xf:set>
</xf:if>

<xf:if is="{$show}">
    some code
</xf:if>

And the some code is always executed whatsoever.

Clément
 
@Mike,

Ah ok well I figured you would say it's as designed.

Could you elaborate a bit about the xf:set ?

I tried using it yesterday and I am unsure of the behavior.
Did that:
HTML:
<xf:set var="$show">0</xf:set>
<xf:if is="a condition">
    <xf:set var="$show">1</xf:set>
</xf:if>

<xf:if is="{$show}">
    some code
</xf:if>

And the some code is always executed whatsoever.

Clément
You set the contentcheck value in the new var, then use it as a condition. If it's empty the whole condition wouldn't trigger.

HTML:
<xf:set var="{$contentcheck}">{$someContent}</xf:set>

<xf:if is="{$contentcheck}">
  <div class="wrappers etc">
    {$contentcheck}
    Something something
  </div>
</xf:if>
You can set multiple variables like that, and it would essentially duplicate contentcheck functionality.
 
In this instance, I believe you would need to use <xf:if is="$contentcheck is not empty"> because it's actually an object. You'd also want to trim it.

Alternatively, we use the <xf:set> style approach in post_macros to determine whether we have an internal action overflow menu. You need to use the "value" style <xf:set> call.
 
Alternatively, we use the <xf:set> style approach in post_macros to determine whether we have an internal action overflow menu. You need to use the "value" style <xf:set> call.
What's the difference between setting it with value attribute and without it?
 
Setting the value via the value attribute will allow you to use any value type. If the value is the tag content then it will need to be a string and it will be converted to a PreEscaped object.
 
More specifically, data between <xf:set>...</xf:set> tags is generally expected to be HTML that you're potentially going to be echoing out later. (As an example, for passing into a macro.) Hence, it's processed as a string and done as an XF\PreEscaped object so it doesn't get double escaped later.

When you're setting a temporary variable for state tracking (like the post_macros example) or when you're not using something that's HTML that you're planning on outputting directly, use the "value" attribute approach. That would be roughly equivalent to you just passing that value through from PHP.
 
Back
Top Bottom