Copied to clipboard

Flag this post as spam?

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


  • Jason Wise 20 posts 100 karma points
    May 16, 2017 @ 13:46
    Jason Wise
    0

    MacroScripts not rendering after upgrade to 7.6.1

    I upgraded to 7.6.1 yesterday and some of my macro scripts are no longer working. Mostly, the macro scripts that are associated with the Blog.

    This is the error I am getting:

    Error loading MacroEngine script (file: /Content/BlogSnip.cshtml)

    This is my code for the BlogSnip.cshtml :

    @using _1040.com.Models
    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
        var root = Model.AncestorOrSelf();
        var blog = root.Descendants("Blog").Take(1)[0];
    
        int lastX = Convert.ToInt32(Parameter.LastX);
        lastX = lastX > 0 ? lastX : 1;  // Default 1
    
        bool promotePost1 = Convert.ToBoolean(Parameter.promotePost1);
    
        // Most recent post with an image
        var posts = root.Descendants("BlogPost").Where("MetaThumb != \"\"").OrderBy("PostDate desc").Take(lastX);
    
        var blogUrl = Library.NodeById(blog.Id).Url;
    
        var firstPost = posts[0];
        var firstPostUrl = ProxyRequest.NormalizeLocalUrl(firstPost.Url);
    
    }
    
    @* Set 1st post to be prominant if shrink false *@
    @if (promotePost1) {
    <article class="post hentry">
        <a href="@firstPostUrl" class="image photo"><img src="@[email protected]" @*width="340" height="289" *@ alt="image description"></a>
        @*<a href="@postUrl" class="alignleft photo"><img src="~/Assets/images/side-hustle-1.jpg" width="340" height="235" alt="image description"></a>*@
    
        @*<a href="@firstPostUrl" class="image photo"><img src="" width="340" height="289" alt="image description"></a>*@
    
        <div class="box">
            @*<span class="category">from the <a href="@blogUrl">blog</a></span>*@
            <h2 class="entry-title"><a href="@firstPostUrl">@firstPost.Name</a></h2>
            @*<span class="meta"><span class="updated published">@firstPost.PostDate.ToString("M/dd/yyyy")</span> | By <span class="fn">@firstPost.Author</span></span>*@
            <div class="blog-teaser">
                @firstPost.Teaser
            </div>
    
            <a href="@firstPostUrl" class="btn">read more</a>
        </div>
    </article>
    

    This is how I am calling the macro script on my homepage:`

    @Umbraco.RenderMacro("BlogTest", new { PromotePost1 = true, LastX = 4 })
    

    Thanks!

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 16, 2017 @ 14:30
    Alex Skrypnyk
    0

    Hi Jason

    Can you look at Umbraco Log what row cause the problem?

    Look here - /AppData/Logs

    Can you debug this site?

    Thanks

    Alex

  • Jason Wise 20 posts 100 karma points
    May 16, 2017 @ 14:42
    Jason Wise
    0

    This is the error message I see in my logs:

    ERROR Umbraco.Core.Persistence.UmbracoDatabase - Exception (7dc9cbed).

    I can debug the site but I do not see anything helpful from that.

    Could I be missing a .dll?

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 16, 2017 @ 14:51
    Alex Skrypnyk
    0

    I don't think that it can be a missing .dll

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 16, 2017 @ 14:48
    Alex Skrypnyk
    0

    I would like to rewrite your macro to this code:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        var root = Umbraco.AssignedContentItem.AncestorOrSelf();
        var blog = root.Descendants("Blog").Take(1);
    
        int lastX = Convert.ToInt32(Model.MacroParameters["LastX"]);
        lastX = lastX > 0 ? lastX : 1;  // Default 1
    
        bool promotePost1 = Convert.ToBoolean(Model.MacroParameters["promotePost1"]);
    
        // Most recent post with an image
        var posts = root.Descendants("BlogPost").Where("MetaThumb != \"\"").OrderBy("PostDate desc").Take(lastX).ToList();
    
        //var blogUrl = Library.NodeById(blog.Id).Url;
    
        var firstPost = posts[0];
        var firstPostUrl = ProxyRequest.NormalizeLocalUrl(firstPost.Url);
    
    }
    
    @* Set 1st post to be prominant if shrink false *@
    @if (promotePost1)
    {
        <article class="post hentry">
            <a href="@firstPostUrl" class="image photo"><img src="@[email protected]" @*width="340" height="289" *@ alt="image description"></a>
            @*<a href="@postUrl" class="alignleft photo"><img src="~/Assets/images/side-hustle-1.jpg" width="340" height="235" alt="image description"></a>*@
    
            @*<a href="@firstPostUrl" class="image photo"><img src="" width="340" height="289" alt="image description"></a>*@
    
            <div class="box">
                @*<span class="category">from the <a href="@blogUrl">blog</a></span>*@
                <h2 class="entry-title"><a href="@firstPostUrl">@firstPost.Name</a>
                </h2>
                @*<span class="meta"><span class="updated published">@firstPost.PostDate.ToString("M/dd/yyyy")</span> | By <span class="fn">@firstPost.Author</span></span>*@
                <div class="blog-teaser">
                    @firstPost.GetPropertyValue("Teaser")
                </div>
    
                <a href="@firstPostUrl" class="btn">read more</a>
            </div>
        </article>
    }
    

    Do not use "Parameter" helper and "@inherits umbraco.MacroEngines.DynamicNodeContext"

    Alex

  • Jason Wise 20 posts 100 karma points
    May 16, 2017 @ 15:00
    Jason Wise
    0

    Alex,

    Thank you for your response! Unfortunately, that solution did not work. I am still getting the same error.

    I am also getting this error too:

    "Error parsing XSLT file: GetMetaTags.xslt "Error parsing XSLT file: GetMetaLinkTags.xslt

    not sure if this has anything to do with it.

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 16, 2017 @ 15:02
    Alex Skrypnyk
    0

    Jason, it's hard to help you when I know so less about your solution.

    Lets look at 'GetMetaTags.xslt' together :)

  • Craig Mayers 164 posts 508 karma points
    May 16, 2017 @ 15:38
    Craig Mayers
    0

    Hi Jason,

    Have you tried completing deleting the cache and regenerating it?

    Cache file can be found @ "/AppData/umbraco.config"

    Delete it and then just do a full re-publish, see if it helps...

    Regards

    Craig

  • Jason Wise 20 posts 100 karma points
    May 16, 2017 @ 16:07
    Jason Wise
    0

    Craig,

    I just tired this and it did not work either. Thanks!

    Jason

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 16, 2017 @ 16:21
    Alex Skrypnyk
    0

    Jason

    It looks like we need to fix all code in your site.

    From which version did you upgrade?

    Alex

  • Jason Wise 20 posts 100 karma points
    May 16, 2017 @ 16:23
    Jason Wise
    0

    I upgraded from 7.3.7

  • Craig Mayers 164 posts 508 karma points
    May 16, 2017 @ 16:39
    Craig Mayers
    0

    Is there anything noticeable in the Log file that may aid us? I.e any errors related to Macros etc.

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 16, 2017 @ 16:54
    Alex Skrypnyk
    0

    Hi Jason

    Did you look at breaking changes?

    Important if you are upgrading an existing site: for the best results:

    In web.config do NOT change useLegacyEncoding to false if it is currently set to true - changing the password encoding will cause you not being able to log in any more In umbracoSettings.config leave EnablePropertyValueConverters set to false - this will help your existing content queries to still work

    https://our.umbraco.org/documentation/Getting-Started/Setup/Upgrading/760-breaking-changes

    Alex

  • Jason Wise 20 posts 100 karma points
    May 18, 2017 @ 13:40
    Jason Wise
    0

    So I think I figured out where the problem is. But I am unsure how to fix it.
    I went into Umbraco Settings and changed the

     var firstPost = posts[0];
    

    and I was able to debug it to the .where in this:

    var posts = root.Descendants("BlogPost").Where("MetaThumb != \"\"").OrderBy("PostDate desc").Take(lastX);
    

    So I am not sure if it is the .Where or the ("MetaThumb..") and I am not sure how to go about fixing it.

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 18, 2017 @ 15:56
    Alex Skrypnyk
    0

    Try this code please:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
        var root = Umbraco.AssignedContentItem.AncestorOrSelf();
        //var blog = root.Descendants("Blog").Take(1);
    
        int lastX = Convert.ToInt32(Model.MacroParameters["LastX"]);
        lastX = lastX > 0 ? lastX : 1;  // Default 1
    
        bool promotePost1 = Convert.ToBoolean(Model.MacroParameters["promotePost1"]);
    
        // Most recent post with an image
        var posts = root.Descendants("BlogPost").Where(x => !string.IsNullOrWhiteSpace(x.GetPropertyValue<string>("MetaThumb"))).OrderByDescending(x => x.GetPropertyValue<DateTime>("PostDate")).Take(lastX).ToList();
    
        //var blogUrl = Library.NodeById(blog.Id).Url;
    
        var firstPost = posts[0];
        var firstPostUrl = ProxyRequest.NormalizeLocalUrl(firstPost.Url);
    
    }
    
    @* Set 1st post to be prominant if shrink false *@
    @if (promotePost1)
    {
        <article class="post hentry">
            <a href="@firstPostUrl" class="image photo"><img src="@[email protected]("MetaThumb")" @*width="340" height="289" *@ alt="image description"></a>
            @*<a href="@postUrl" class="alignleft photo"><img src="~/Assets/images/side-hustle-1.jpg" width="340" height="235" alt="image description"></a>*@
    
            @*<a href="@firstPostUrl" class="image photo"><img src="" width="340" height="289" alt="image description"></a>*@
    
            <div class="box">
                @*<span class="category">from the <a href="@blogUrl">blog</a></span>*@
                <h2 class="entry-title">
                    <a href="@firstPostUrl">@firstPost.Name</a>
                </h2>
                @*<span class="meta"><span class="updated published">@firstPost.PostDate.ToString("M/dd/yyyy")</span> | By <span class="fn">@firstPost.Author</span></span>*@
                <div class="blog-teaser">
                    @firstPost.GetPropertyValue("Teaser")
                </div>
    
                <a href="@firstPostUrl" class="btn">read more</a>
            </div>
        </article>
    }
    
  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    May 18, 2017 @ 15:57
    Alex Skrypnyk
    0

    Jason, change, please retrieving of posts to :

    var posts = root.Descendants("BlogPost").Where(x => !string.IsNullOrWhiteSpace(x.GetPropertyValue<string>("MetaThumb"))).OrderByDescending(x => x.GetPropertyValue<DateTime>("PostDate")).Take(lastX).ToList();
    

    Then you will be able to debug and it should fix this issue.

  • Craig Mayers 164 posts 508 karma points
    May 18, 2017 @ 13:50
    Craig Mayers
    0

    Hi Jason,

    What is "MetaThumb" ?

    Looks like your passing it as a string. Have you used Lambada Expressions before?

    You could do something like this:

    var posts = root.Descendants("BlogPost").Where(x => x.MetaThumb != "").OrderBy("PostDate desc").Take(lastX);
    

    x.MetaThumb - being a strongly-typed property of a node (IPublishedContent)

    OR

    var posts = root.Descendants("BlogPost").Where(x => x.GetPropertyValue("MetaThumb") != "").OrderBy("PostDate desc").Take(lastX);
    
Please Sign in or register to post replies

Write your reply to:

Draft