Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicolai 48 posts 201 karma points
    Mar 27, 2015 @ 12:39
    Nicolai
    0

    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:

    @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?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 27, 2015 @ 12:52
    Jeavon Leopold
    101

    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

  • Nicolai 48 posts 201 karma points
    Mar 27, 2015 @ 13:19
    Nicolai
    0

    Worked like a charm! Thank you so much Jeavon.

    -Nicolai

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 27, 2015 @ 13:23
    Jeavon Leopold
    0

    Fab, you're welcome!

Please Sign in or register to post replies

Write your reply to:

Draft