Developer forum

Forum » Development » Weird boolean behavior when editing items

Weird boolean behavior when editing items

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

 

I tried to make editing of item types work using the default templates, but the default templates didn't render the edit links. I then modified the code as follows to test things out:

<!--@LoopStart(ItemPublisher:Items.List)-->
    If Defined Can Edit: <!--@If Defined()-->Is Defined<!--@EndIf(ItemPublisher:Items.CanEdit)--><br />
    If Not Defined Can Edit: <!--@If Not Defined(ItemPublisher:Items.CanEdit)-->Is Not Defined<!--@EndIf(ItemPublisher:Items.CanEdit)--><br />
    Value <!--@ItemPublisher:Items.CanEdit-->
 <!--@LoopEnd(ItemPublisher:Items.List)-->

The outcome is this:

 

If Defined Can Edit:
If Not Defined Can Edit: Is Not Defined
Value True

 

So the tag is NOT defined, yet its value is True.

 

Not sure what's going on. Either Not Defined no longer works on booleans in which case the second tag should be empty too. Or the tag does work on booleans and I would expect it to be true. What's going on here?

 

Either way, I think the templates (/Files/Templates/ItemPublisher/List\List.html in my case) need an update....

 

Cheers,

 

Imar


Replies

 
Nicolai Høeg Pedersen
Reply

I've send this one to QA - they will see if it is a bug and have it fixed for 8.2.3 if that is the case.

 

BR Nicolai

 
Mikkel Ricky
Reply

This may not be a bug, but a feature …

First the fix: You're using  inside the ItemPublisher:Items.List loop, but you should actually use , i.e. singular (Item) rather than plural (Items).

Now for the explanation of the observed behaviour: When Dynamicweb evaluates conditions, only tags defined in the current context, in this case inside the ItemPublisher:Items.List loop, are considered. So you're checking if the tag ItemPublisher:Items.CanEdit is defined inside the loop. It is not defined and therefore the content inside @If Not Defined(…) is rendered. Dynamicweb doesn't remove undefined tags, so the rendered loop content will look like this

  If Defined Can Edit: <br />
  If Not Defined Can Edit: Is Not Defined<br />
  Value <!--@ItemPublisher:Items.CanEdit-->

After the loop has been rendered, the template containing the loop is rendered and in this context the tag  exists and has the value True. Therefore, the final result after first rendering the loop and then rendering the template will be

  If Defined Can Edit: <br />
  If Not Defined Can Edit: Is Not Defined<br />
  Value True

Hence, it may not be a bug, but a feature. Probably a somewhat confusing one, but still a feature.

Best regards,
Mikkel

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi Mikkel,

 

Thanks for the clarification. It makes perfect sense this way. That does mean however that the default templates have a "bug"; the files in Admin/Update/Files/Templates/ItemPublisher/List that are added to the site's Templates folder during an update use Items rather than Item to determine if editing links should be rendered. Should I log this as a separate case or can you do it based on this post?

Imar

 

 

 

 
Mikkel Ricky
Reply

The typo/bug in our default templates has been fixed and will be released in Dynamicweb 8.2.3 on May 27.

 

You must be logged in to post in the forum