Copied to clipboard

Flag this post as spam?

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


  • JJ 15 posts 35 karma points
    Nov 22, 2012 @ 10:33
    JJ
    0

    v4.10.1 Razor Macro error in unpublished page in Editor

    [umbraco v 4.10.1 (Assembly version: 1.0.4701.30218)]

    Just using a simple Hello World razor script Macro:

    "<h1> Hello World</h1>"

    Which the checkboxes "enable in editor" and "render in editor" are checked, I get the following error when I try to insert it via the Richtext editor:

    Error loading MacroEngine script (file: HelloWorld.cshtml)

    However, when I publish the page, THEN insert the macro, it works as expected.

    Is this a bug or am I missing something obvious?

    Thanks,

    JJ

  • JJ 15 posts 35 karma points
    Nov 22, 2012 @ 10:49
    JJ
    0

    Just to double confirm this: Unpublishing the page brings the above issue back within the editor.

    It will only work on an unpublished page if the "render in editor" is removed.

    As I'm passing no parameters, and this is as simple as a razor macro can get,  am I correct in assuming this is a bug?

     

    Thanks,

    JJ

  • JJ 15 posts 35 karma points
    Nov 22, 2012 @ 11:04
    JJ
    0

    Really appreciate it if anyone else could check if this is happening on your version 4.10.0 or 4.10.1 installs.

    Seems like someone else must have discovered this before me?

  • Stephen 767 posts 2273 karma points c-trib
    Nov 22, 2012 @ 12:02
    Stephen
    0

    This is happening in all versions because the macro wants a current page (XLST) ie a Model (Razor) that it can't find since the document is not published and therefore not in the XML cache. That was the case in 4.9 and is still the case in 4.10 and 4.11. So this sort of is "expected behavior".

    Granted, the error message could be more explicit about it.

    And the ultimate fix will be to entirely replace the XML cache (work-in-progress, it seems) by a cache that will give easy access to preview content. Then macros could run on the preview content and render, even though the content is not yet published.

  • JJ 15 posts 35 karma points
    Nov 22, 2012 @ 12:23
    JJ
    0

    Thanks Stephen.

    So are you saying that this would happen whether it was a Razor or XSLT Macro?

    The error message should really not be an 'error' but a 'not able to be rendered on an unpublished page' rather similar to the message you get when you uncheck the 'render in editor' checkbox.

    The way Umbraco/Richtext editor deals with macro's  is causing me some real headaches - that dotted box in the editor and the extra <p></p> it places completely destroys the layout. My macro places a small superscript symbol with a link so needs to be placed precisely and without theses extra unwanted tags.

     Thanks,

    JJ

  • Stephen 767 posts 2273 karma points c-trib
    Nov 22, 2012 @ 12:41
    Stephen
    0

    I _think_ it would happen both in Razor and XSLT and yes, the message should be different.

    As for inserting non-intrusive macros... not supported at the moment although that's a thing I'd like to see fixed too.

  • JJ 15 posts 35 karma points
    Nov 22, 2012 @ 14:23
    JJ
    0

    I've managed to remove the surrounding </p> and <p> of the bodyText which is inserted by the RichText editor, via the code behind of my masterpage.

    However, the inital page render still shows the unchanged html. The second refresh shows the changed html correctly, so clearly I am not intercepting the rendering pipline in the right place. Can anyone advise?

    I've tried overriding PreRender and PreInit and changin the bodyText there, but clearly the rendering is taking place before I change the field. This is what I'm doing:

    protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e); //I've tried moving this to the bottom too

            // Get the document by its ID
            Document doc = new Document(Node.GetCurrent().Id);

            if (doc.Published)//otherwise we'll end up publishing a page after replacing tags, that isn't meant to be
            {
                // Get the properties to modify:
                string newBodyText = doc.getProperty("bodyText").Value.ToString();

                ////CODE HERE TO REMOVE unwanted </p><p> from var newBodyText///

         //Now update the field:
                doc.getProperty("bodyText").Value = newBodyText;
         // After modifying the document, prepare it for publishing
                User author = User.GetUser(0);
                doc.Publish(author);

                // Tell umbraco to publish the document so the updated properties are visible on website
                umbraco.library.UpdateDocumentCache(doc.Id);
               
            }
        }

     

Please Sign in or register to post replies

Write your reply to:

Draft