Developer forum

Forum » CMS - Standard features » Errors when trying to query Item Fields with razor?..

Errors when trying to query Item Fields with razor?..

Mikkel Toustrup Olsen
Reply

Hello,

I'm ran into a few problems when I tried to query my Item's fields/properties with razor in a oaragraph template (.cshtml) of course.

My code is the following..

@{

var img = @GetValue(Item.NameOfProperty) -> In my case var img = @GetValue(Item.Billede) ;

 }

and hereafter <img src="@img" etc... />

Am I missing something or do I have a syntax error - I can't quite figure it out.

Thanks :-)

 

 

 

 

 


Replies

 
Mikkel Ricky
Reply

The argument to GetValue must be a string, i.e. you have to put quotes around Item.Billede:

@GetValue("Item.Billede")

If you still cannot make it work, then please post your complete paragraph template here.

 
Mikkel Toustrup Olsen
Reply

Hmm, It does not seem to find my item in question. My paragraph template looks like this (though it isnt much) - only for testing purposes atm. which only need to show the image set in the .Billede field.

@{ var img = @GetValue("Item.Billede"); }

 

--------- EDIT -----------

 

For some reason my template wasn't saved - it works now perfectly!

 

 

 

 

 

 

 

 

You must be logged in to post in the forum