Developer forum

Forum » Templates » HTML Template : if startswith space

HTML Template : if startswith space

Gaetan Di Caro
Reply

Hello,

 

At some point in my code I must test for the content of a custom user field. This field comes directly from the data integration and contains either a real value, or just spaces. I haven't found a way to trim it on import in the job.

However in the html template I can't seem to be able to test that. I haven't found a function to trim the spaces and compare to ''.

So I do this :

<!--@If Defined(UserManagement:User.AccessUser_MyField)-->test<!--@EndIf-->

Doesn't work, it displays "test" whether the value is only spaces or not. So I try this instead (testing if it starts with an empty space):

<!--@If(UserManagement:User.AccessUser_MyField<startswith>' ')-->test<!--@EndIf-->

Well, doesn't work either. Seems like the test is always true no matter the value of "MyField".

 

Do you have any idea how I could solve this ?

 

Thanks !


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Gaetan

You could shift to Razor and do the test there... Best option.

You can also use the Replace tag extension in your conditional: http://templates.dynamicweb.com/TemplateTags/Dynamicweb-template-tags/General-tags/Tag-extensions.aspx

<!--@If Defined(UserManagement:User.AccessUser_MyField.Replace(' ', ''))-->test<!--@EndIf-->

Votes for this answer: 1
 
Gaetan Di Caro
Reply

I'd much rather go razor if it was an option, but I'm only making a minor evolution on an older solution ;)

But your solution seems to work fine, thanks !

 

You must be logged in to post in the forum