Copied to clipboard

Flag this post as spam?

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


  • Craig100 1136 posts 2523 karma points c-trib
    Jun 05, 2012 @ 16:10
    Craig100
    0

    Have friendly Urls stopped this Macro working?

    Hi,

    On a new 4.7.2 site I had this marcro working then switched the site to use friendly URL's iaw http://our.umbraco.org/wiki/install-and-setup/setting-up-umbraco-for-friendly-urls. Everything works fine except this newslisting Razor macro and I can't see why.  Can anyone give me a clue?

    TIA

    Craig

    @{
      var pagesToList = @Model.Children.Where("Visible");  
          foreach (var newsItem in pagesToList)
          {
              var newsCopy = newsItem.articleExcerpt;
              newsCopy = Library.StripHtml(newsCopy);
              newsCopy = Library.Truncate(newsCopy, 200, true);
             
              var newsImage = newsItem.newsListImage.umbracoFile;
           
              <article class="newsItem">
               <a href="@newsItem.Url"><img src="/ImageGen.ashx?image=@newsImage&AltImage=noimage-newslist.gif&width=200" alt="@newsItem.summaryHeadline"></a>    
               <h3><a href="@newsItem.Url">@newsItem.summaryHeadline</a></h3>
               <p>@newsCopy</p>
              </article>
          }
    }

  • Rik Helsen 670 posts 873 karma points
    Jun 05, 2012 @ 17:06
    Rik Helsen
    0

    what is it outputting? an error or only partial html?

  • Craig100 1136 posts 2523 karma points c-trib
    Jun 05, 2012 @ 17:41
    Craig100
    0

    It's outputting: Error loading MacroEngine script (file: NewsList.cshtml) 

    I did try to edit my post put the system croaked!

    The macro is embedded with 

      <section class="main">

        <h1><umbraco:Item field="contentTitle" runat="server" /></h1>

        <umbraco:Macro Alias="NewsList" runat="server" />   

      </section >

    (now for some reason there's not "code" formatting option!!)

  • Craig100 1136 posts 2523 karma points c-trib
    Jun 05, 2012 @ 17:45
    Craig100
    0

    I tried changing @newsItem.Url to @newsItem.NiceUrl but I think the problem's a bit more fundamental than that.

  • Craig100 1136 posts 2523 karma points c-trib
    Jun 05, 2012 @ 18:17
    Craig100
    0

    I tried undoing the changes detailed in  our.umbraco.org/.../setting-up-umbraco-for-friendly-urls. expecting it all to continue working but it doesn't. I'm right in it now with a deadline to hit!!!!  What has happened to this macro just by changing the umbracoUseDirectoryUrls param from falst to true and adding preCondition="" to the end of  UrlRewriteModule? It appears I'm not the only one with this problem (http://our.umbraco.org/forum/core/general/26053-Error-loading-Macro-Engine-script-after-changing-umbracouseDirectoryUrls), no solution though:(

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Jun 05, 2012 @ 19:40
    Warren Buckley
    1

    Hello Craig,
    I would recommend a few things first, let's see if we can get some more info on the error by adding the debug querystring to the URL
    ?umbdebugshowtrace=true

    If you can post any details about errors/exceptions from that then we can try and figure out what is causing the issue.

    Secondly ensure everything is all OK with the macro, by removing the logic you have and making a backup of it of course and putting something like
    Hello World inside it. That way if it loads we can now pinpoint its a problem with the logic rather than a problem loading that particular macro.

    This will at least give us a starting point. 

    Cheers,
    Warren 

     

  • Craig100 1136 posts 2523 karma points c-trib
    Jun 05, 2012 @ 19:59
    Craig100
    0

    Hi Warren,

    Didn't know there was a debug facility (or I'd forgotten!)

    The part of the trace in red which appears to be an error is:-

     

    umbracoMacroError Loading Razor Script (file: Get News Items List) 'string' does not contain a definition for 'umbracoFile'    at CallSite.Target(Closure , CallSite , Object )  at ASP._Page_macroScripts_GetNewsItemsList_cshtml.Execute() in c:\Users\Craig\Documents\My Web Sites\GabeLeonard\macroScripts\GetNewsItemsList.cshtml:line 9

      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()

      at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)

      at System.Web.WebPages.WebPage.ExecutePageHierarchy()

      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)

      at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)

      at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)0.009395199234140230.000190

    umbracoMacroLoading IMacroEngine script [done]0.009430373664867450.000035

    umbracoMacroError loading MacroEngine script (file: GetNewsItemsList.cshtml, Type: ''

    'string' does not contain a definition for 'umbracoFile'

      at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)0.009488393344417510.000058

     

     

    Notiing the 'string' does not contain a definition for 'umbracoFile' I removed the call for var newsImage and the line outputting it to ImageGen and the script now loads:-

     

    @{
     
    var pagesToList =@Model.Children.Where("Visible");  
         
    foreach(var newsItem in pagesToList)
         
    {
             
    var newsCopy = newsItem.articleExcerpt;
              newsCopy
    =Library.StripHtml(newsCopy);
              newsCopy
    =Library.Truncate(newsCopy,200,true);
           
             
    <article class="newsItem">  
               
    <h3><a href="@newsItem.Url">@newsItem.summaryHeadline</a></h3>
               
    <p>@newsCopy</p>
              </
    article>
         
    }
    }

     

     

    (no code formatting available on replies btw!)

    However, before changing to niceUrls the original code worked very nicely thankyou. So I suppose the question is then how to re-instigate the following lines so they work with nice URLs:-

     

    var newsImage = newsItem.newsListImage.umbracoFile;
    <a href="@newsItem.Url"><img src="/ImageGen.ashx?image=@newsImage&AltImage=noimage-newslist.gif&width=200" alt="@newsItem.summaryHeadline"></a>

     

     

    Craig

  • Craig100 1136 posts 2523 karma points c-trib
    Jun 05, 2012 @ 20:06
    Craig100
    0

    Hi Warren,

    On a hunch I removed .umbracoFile, expecting to just see the image ID rendered, as it had before when I wrote the change to the macro. Now, it works!

    As this is rather counter intuitive (to me at any rate) it would be good if someone could explain why just var newsImage = newsItem.newsListImage now ouputs a path instead of just an ID which it had before I instigated the niceURL changes.

    Regards,

    Craig


Please Sign in or register to post replies

Write your reply to:

Draft