Developer forum

Forum » Templates » if statement - compare dw-tag with customfield

if statement - compare dw-tag with customfield

Filip Lundby
Reply

Hi,

I'd like to compare two variables - to see if Global:Extranet.Groups contains a custom-field value. Like this:

<!--@If Not(Global:Extranet.Groups<contains>Ecom:Product:Field.HideForGroup.Value.Clean)-->
	Do not show for group 300.
<!--@EndIf-->
  
<!--@If (Global:Extranet.Groups<contains>Ecom:Product:Field.HideForGroup.Value.Clean)-->
	Show for group 300.
<!--@EndIf-->

 

In Management Center the field is created as a custom product field - String/text 255.

In usermanagement I've added my user to a group with the ID 300. 

In eCommerce I've added 300 in my custom-field to a single product.

On the website frontend I'm logged in and added the above if-statements to the Products-loop in the productlist.

 

"Show for group 300." will always be outputted no matter if the customfield contains a value or not.

Any ideas?

 


Replies

 
Mikkel Ricky
Reply

In what context are you writing this, i.e. are you inside the Products loop? If possible, please post (or link to) the complete template.

Best regards,
Mikkel

 

 

 
Nicolai Høeg Pedersen
Reply

Hi Filip

 

It is because your right side of the conditional, Ecom:Product:Field.HideForGroup.Value.Clean, is string.empty when you do not add a number on the field in the admin. So you will ask if the groups contains string.empty, and it does.

 

So your conditional should look more like this:

 

<!--@If(Ecom:Product:Field.HideForGroup<>'' && Global:Extranet.Groups<contains>Ecom:Product:Field.HideForGroup)-->

<!--@EndIf-->

Br Nicolai

 
Filip Lundby
Reply

Thanks Nicolai!

 

You must be logged in to post in the forum