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
hello Our.Umbraco
I got a problem with my macro.
Here's the Code
@inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var selection = CurrentPage.Children.Where("Visible"); } @if (selection.Any()) { var count = 0; foreach (var item in selection) { if(count % 2 == 0) { <div class="row"> <div class="col-sm-1 col-xs-0"> </div> <div class="col-sm-5 col-xs-12"> <p class="text">@item.Datum</p> <label class="subtitle">@item.Anlass</label><br /><br /> </div> } else { <div class="col-sm-5 col-xs-12 text"> <p class="text">@item.Datum</p> <label class="subtitle">@item.Anlass</label><br /><br /> </div> </div> } count++; } }
my problem is, it doesn't read the "else" statement. It puts out "} else {". It looks like its putting it out as html and not reading it as a macro.
What did i do wrong?
i think i got it.. i have to put @: in front of every code that is HTML. like:
@inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var selection = CurrentPage.Children.Where("Visible"); } @if (selection.Any()) { var count = 0; foreach (var item in selection) { if(count % 2 == 0) { @:<div class="row"> @:<div class="col-sm-1 col-xs-0"> @:</div> @:<div class="col-sm-5 col-xs-12"> @:<p class="text">@item.Datum</p> @:<label class="subtitle">@item.Anlass</label><br /><br /> @:</div> } else { @:<div class="col-sm-5 col-xs-12 text"> @:<p class="text">@item.Datum</p> @:<label class="subtitle">@item.Anlass</label><br /><br /> @:</div> @:</div> } count++; } }
Hi Hubert
that is an intresting solution i never knew you could do that. :)
but it should work the other way.
looking at the code i think it's because you have a missing / extra div inside the if (relating to the <div class="row">)
<div class="row">
if you move the first div outside of if and the lass div from the else.
foreach (var item in selection) { <div class="row"> @if(count % 2 == 0) { <div class="col-sm-1 col-xs-0"> </div> <div class="col-sm-5 col-xs-12"> <p class="text">@item.Datum</p> <label class="subtitle">@item.Anlass</label><br /><br /> </div> } else { <div class="col-sm-5 col-xs-12 text"> <p class="text">@item.Datum</p> <label class="subtitle">@item.Anlass</label><br /><br /> </div> } </div>
then that should work (note the @ in front of the if statement now because it's inside the div)
if
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
if/else problem
hello Our.Umbraco
I got a problem with my macro.
Here's the Code
my problem is, it doesn't read the "else" statement. It puts out "} else {". It looks like its putting it out as html and not reading it as a macro.
What did i do wrong?
i think i got it.. i have to put @: in front of every code that is HTML. like:
Hi Hubert
that is an intresting solution i never knew you could do that. :)
but it should work the other way.
looking at the code i think it's because you have a missing / extra div inside the if (relating to the
<div class="row">
)if you move the first div outside of if and the lass div from the else.
then that should work (note the @ in front of the
if
statement now because it's inside the div)is working on a reply...