Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi there.
I have a simple inline if statement in my template that tests for a field value then displays appropriate html.
The code is as follows:
@if (Model.HasValue("dL3strippingDims")) { var family = Model.connectorFamily; var dl3 = Model.Media("dL3strippingDims"); <tr> @if (family="Inter Series Adaptor") { <td width="20%">Stripping Dimensions</td> } else { <td width="20%">Int Dims 2</td> } <td width="80%"><a href="@dl3.umbracoFile" target="_blank">@dl3.Name</a></td> </tr> }
I thought I knew how to do this, but I guess my razor syntax is awry - I get the error message
Error loading MacroEngine script (file: )
(If I just display the value of the var "family" it works fine and displays "Inter Series Adaptor" as I would expect.
Any ideas or guidance gratefully received.
Thanks Ben
Hi Ben,
I have just tried to work with your code, and I think I found a solution for you.
The thing that gives you the error is your if statement where you try to check if the variable called family is equal to Inter Series Adaptor
Try this code instead:
@if (Model.HasValue("dL3strippingDims")){ var family = Model.connectorFamily; var dl3 = Model.Media("dL3strippingDims"); <tr> @if (family == "Inter Series Adaptor") { <td width="20%">Stripping Dimensions</td> } else { <td width="20%">Int Dims 2</td> } <td width="80%"><a href="@dl3.umbracoFile" target="_blank">@dl3.Name</a></td> </tr> }
When you try to check if a variable has a particular string value, then use two equal signs.
I hope it helps,
/Dennis
Hey Dennis,
Works a charm! Can't believe I missed that.
Thanks very much.
Ben
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Razor - "simple" inline if statement causes MacroEngine error
Hi there.
I have a simple inline if statement in my template that tests for a field value then displays appropriate html.
The code is as follows:
I thought I knew how to do this, but I guess my razor syntax is awry - I get the error message
(If I just display the value of the var "family" it works fine and displays "Inter Series Adaptor" as I would expect.
Any ideas or guidance gratefully received.
Thanks Ben
Hi Ben,
I have just tried to work with your code, and I think I found a solution for you.
The thing that gives you the error is your if statement where you try to check if the variable called family is equal to Inter Series Adaptor
Try this code instead:
When you try to check if a variable has a particular string value, then use two equal signs.
I hope it helps,
/Dennis
Hey Dennis,
Works a charm! Can't believe I missed that.
Thanks very much.
Ben
is working on a reply...