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
Im trying to convert a script file to an partial view macro file but im getting the error:
"Error loading Partial View script (file: ~/Views/MacroPartials/FrontPageSlider.cshtml)"
Im pretty sure that some of my syntax is wrong. (Maybe at the line where the code "@:" is written)?
Scripting File:
@inherits umbraco.MacroEngines.DynamicNodeContext@using umbraco.MacroEngines@{ var sliderItems = Library.NodeById(5021); @*var sliderItems = Model.AncestorOrSelf(1).DescendantsOrSelf("FrontpageSliderItems").First();*@ <div id="myCarousel" class="carousel slide"> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <div class="carousel-inner"> @foreach (var item in sliderItems.Children.OrderBy("Id desc")) { var magazine = item.NodeById(item.frontpageSliderItemId); if (item.IsFirst()) { @:<div class="item active"> }else{ @:<div class="item"> } <div class="container"> <a href="@magazine.Url"> @if (item.HasValue("frontpageSliderItemImage")) { <img src="@item.Media("frontpageSliderItemImage","umbracoFile")" /> } </a> <div class="carousel-headline"> <h1><a href="@magazine.Url">TEMA: @magazine.magazineTitle</a> <span>@magazine.magazineIssue</span></h1> </div> <a href="#"> <div class="sliderlines"> @if (item.HasValue("frontpageSliderItemArticleOneId")) { var article = item.NodeById(item.frontpageSliderItemArticleOneId); <div class="sliderline line-1"><a href="@article.Url">@article.homepageArticleTitle</a></div> } @if (item.HasValue("frontpageSliderItemArticleTwoId")) { var article = item.NodeById(item.frontpageSliderItemArticleTwoId); <div class="sliderline line-2"><a href="@article.Url">@article.homepageArticleTitle</a></div> } @if (item.HasValue("frontpageSliderItemArticleThreeId")) { var article = item.NodeById(item.frontpageSliderItemArticleThreeId); <div class="sliderline line-3"><a href="@article.Url">@article.homepageArticleTitle</a></div> } @if (item.HasValue("frontpageSliderItemArticleFourId")) { var article = item.NodeById(item.frontpageSliderItemArticleFourId); <div class="sliderline line-4"><a href="@article.Url">@article.homepageArticleTitle</a></div> } </div> </a> </div> @:</div> } </div> </div> <br />}
Partial View Macro File:
@inherits Umbraco.Web.Macros.PartialViewMacroPage@{ var sliderItems = Umbraco.Content(5021); <div id="myCarousel" class="carousel slide"> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <h6>Hey</h6> <div class="carousel-inner"> @foreach (var item in sliderItems.Children.OrderBy("Id desc")) { var magazine = item.DocumentTypeAlias(item.frontpageSliderItemId); var sliderImage = Umbraco.Media(item.frontpageSliderItemImage); if (item.IsFirst()) { @:<div class="item active"> }else{ @:<div class="item"> } <div class="container"> <a href="@magazine.Url"> @if (item.HasValue("frontpageSliderItemImage")) { <img src="@sliderImage.umbracoFile" /> } </a> <div class="carousel-headline"> <h1><a href="@magazine.Url">TEMA: @magazine.magazineTitle</a> <span>@magazine.magazineIssue</span></h1> </div> <a href="#"> <div class="sliderlines"> @if (item.HasValue("frontpageSliderItemArticleOneId")) { var article = item.NodeById(item.frontpageSliderItemArticleOneId); <div class="sliderline line-1"><a href="@article.Url">@article.homepageArticleTitle</a></div> } @if (item.HasValue("frontpageSliderItemArticleTwoId")) { var article = item.NodeById(item.frontpageSliderItemArticleTwoId); <div class="sliderline line-2"><a href="@article.Url">@article.homepageArticleTitle</a></div> } @if (item.HasValue("frontpageSliderItemArticleThreeId")) { var article = item.NodeById(item.frontpageSliderItemArticleThreeId); <div class="sliderline line-3"><a href="@article.Url">@article.homepageArticleTitle</a></div> } @if (item.HasValue("frontpageSliderItemArticleFourId")) { var article = item.NodeById(item.frontpageSliderItemArticleFourId); <div class="sliderline line-4"><a href="@article.Url">@article.homepageArticleTitle</a></div> } </div> </a> </div> @:</div> } </div> </div> <br />}
Can anyone help me figure out where im going wrong?
Hi Nicolai,
You have a few NodeById methods which needs to be switched to Umbraco.Content. Try this:
@inherits Umbraco.Web.Macros.PartialViewMacroPage @{ var sliderItems = Umbraco.Content(5021); <div id="myCarousel" class="carousel slide"> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <h6>Hey</h6> <div class="carousel-inner"> @foreach (var item in sliderItems.Children.OrderBy("Id desc")) { var magazine = Umbraco.Content(item.frontpageSliderItemId); var sliderImage = Umbraco.Media(item.frontpageSliderItemImage); if (item.IsFirst()) { @:<div class="item active"> } else { @:<div class="item"> } <div class="container"> <a href="@magazine.Url"> @if (item.HasValue("frontpageSliderItemImage")) { <img src="@sliderImage.umbracoFile" /> } </a> <div class="carousel-headline"> <h1><a href="@magazine.Url">TEMA: @magazine.magazineTitle</a> <span>@magazine.magazineIssue</span></h1> </div> <a href="#"> <div class="sliderlines"> @if (item.HasValue("frontpageSliderItemArticleOneId")) { var article = Umbraco.Content(item.frontpageSliderItemArticleOneId); <div class="sliderline line-1"><a href="@article.Url">@article.homepageArticleTitle</a></div> } @if (item.HasValue("frontpageSliderItemArticleTwoId")) { var article = Umbraco.Content(item.frontpageSliderItemArticleTwoId); <div class="sliderline line-2"><a href="@article.Url">@article.homepageArticleTitle</a></div> } @if (item.HasValue("frontpageSliderItemArticleThreeId")) { var article = Umbraco.Content(item.frontpageSliderItemArticleThreeId); <div class="sliderline line-3"><a href="@article.Url">@article.homepageArticleTitle</a></div> } @if (item.HasValue("frontpageSliderItemArticleFourId")) { var article = Umbraco.Content(item.frontpageSliderItemArticleFourId); <div class="sliderline line-4"><a href="@article.Url">@article.homepageArticleTitle</a></div> } </div> </a> </div> @:</div> } </div> </div> <br /> }
Jeavon
Worked like a charm! Thank you so much Jeavon.
-Nicolai
Fab, you're welcome!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Converting from Scripting File to Partial View Macro File.
Im trying to convert a script file to an partial view macro file but im getting the error:
"Error loading Partial View script (file: ~/Views/MacroPartials/FrontPageSlider.cshtml)"
Im pretty sure that some of my syntax is wrong. (Maybe at the line where the code "@:" is written)?
Scripting File:
Partial View Macro File:
Can anyone help me figure out where im going wrong?
Hi Nicolai,
You have a few NodeById methods which needs to be switched to Umbraco.Content. Try this:
Jeavon
Worked like a charm! Thank you so much Jeavon.
-Nicolai
Fab, you're welcome!
is working on a reply...