Developer forum

Forum » Templates » If statements with custom fields

If statements with custom fields

Nikki Strømsnes
Reply
Hi guys,

I'm making a product list, where I would like to add some extra elements, depending on the values of the product. For example, if a product is discounted or new to the stock, a teaserbox should display to grab the attention of the user. We have some custom checkbox fields, that return a boolean for these cases.

Now, this works exactly as expected, as long as I have a DwTemplateTags on the page. If I remove that, the if statements are skipped!  

I figured it might have something to do with the custom fields, so I tried using the standard price tags and compared those (e.g. ), however that didn't do any difference. Since the values are always defined as either true or false, I can not use an If Defined, and the client is really reluctant to make changes as to how the database works.

Any ideas?
<!--@LoopStart(Products)-->
  
    <div>This div and all tags inside it show perfectly</div> 
  
   <!--@If(Ecom:Product:Field.IsNew.Value=True)-->
        <div>New!</div> 
    <!--@EndIf-->
  
    <!--@DwTemplateTags-->
  
<!--@LoopEnd(Products)-->
 

  

Replies

 
Nikki Strømsnes
Reply
Hmm, it turns out this is not limited to If statements. I also can't get any output from some custom fields, unless there's a DwTemplateTags somewhere on the page. Mighty strange. :S 
 
Yury Zhukovskiy
Reply
Hi, Try to remove compare to True from IF tag:
 <!--@If(Ecom:Product:Field.IsNew.Value)-->

If it will not help, provide please link to the page

KR
Zhukovskiy Yury

 
Nikki Strømsnes
Reply
Thanks for your reply, Yury.

I can print it out just fine by itself, and I can even make the [If value=true] comparison to work just as I want it to — but only as long as I have a DwTemplateTags in the same loop, otherwise the tag/statement is simply not rendered. As it is not exclusive to this page, I've come to the conclusion that it must be some strange bug.

Best regards,
Nikki Strømsnes
 
Nikki Strømsnes
Reply
It turned out to be a bug in the Dw core, that will (hopefully) get fixed in the next SR. Anyway, I found a workaround for the if statement. Fortunately, this was one of the custom tags that I could actually get some output of on its own, so I simply inserted it as a CSS class, and used it to toggle the display. It doesn't look that pretty, but it works. Sadly, I will have to wait for the SR for the other tags to work. >.<

<div class="show<!--@Ecom:Product:Field.isNew.Value-->">New!</div>
.showTrue { display:block; }
.showFalse { display:none; }

 

You must be logged in to post in the forum