Developer forum

Forum » Templates » If Defined in Razor

If Defined in Razor

Hans Ravnsfjall
Reply

Hi

Probably a really simple solution to this question, but how can i use the if defined functions from the old templates, in Razor

 

How would i wrap this in an If Defined?

<img src='@GetValue("Item.Mynd.Value")' alt='@GetValue("Item.Yvirskrift.Value")' />

 

Or in other words, i want to translate this to razor

 <!--@If Defined(Item.Mynd.Value)-->

<img src="<!--@Item.Mynd.Value-->" alt="<!--@Item.Yvirskrift.Value-->" />

<!--@EndIf(Item.Mynd.Value)-->

 

Aprecieate your help


Replies

 
Thomas Schroll
Reply

Hi Hans

I would do it like this:

@if(!string.IsNullOrEmpty(GetString("Item.Mynd"))){

<img src='@GetString("Item.Mynd")' alt='@GetString("Item.Yvirskrift")'/>

}

Remember to either put HTML attributes in single qoutes or store the value from DW in a variable first.

Regards Thomas

 
Thomas Schroll
Reply

Hi Hans

I would do it like this:

@if(!string.IsNullOrEmpty(GetString("Item.Mynd"))){

<img src='@GetString("Item.Mynd")' alt='@GetString("Item.Yvirskrift")'/>

}

Remember to either put HTML attributes in single qoutes or store the value from DW in a variable first.

Regards Thomas

 
Merethe Vrå Andersen
Reply

Hi,

You might be able to find some help here when changing from html to razor templates:
https://github.com/dynamicweb/razor/wiki/Getting-started-with-Razor
https://github.com/dynamicweb/razor/wiki/From-Dynamicweb-HTML-to-Razor

Kind regards,

Merethe

 

 

You must be logged in to post in the forum