Copied to clipboard

Flag this post as spam?

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


  • IanS 22 posts 65 karma points
    Feb 23, 2015 @ 17:50
    IanS
    0

    Partial view macro not working in RTE - Error is Failed to retrieve macro result for macro with alias

    I have a simple partial view macro that I'm using to render YouTube embed code in to the RTE.  When I add it though, I get an error "Failed to retrieve macro result for macro with alias". In the logs I get an error "Error loading Partial View (file: ~/Views/MacroPartials/YouTubeVideo.cshtml). Exception: System.ArgumentNullException: Value cannot be null.
    Parameter name: content"

    The macro code is:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        string videoID = (string)@Model.MacroParameters["videoID"];
    }
    <div class="iframe-wrapper"><iframe src="//www.youtube-nocookie.com/embed/@videoID"></iframe></div>

    Any ideas what is going wrong.  It often works ok if I publish straight away but always fails on first load or when I preview it. 

    Using Umbraco version 7.1.4

    Thanks!

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Feb 23, 2015 @ 17:54
    Jan Skovgaard
    0

    Hi Ian

    Are you using MVC or Webforms? And have you tried having a look in the /App_Data/Logs file? It should contain more detailed information about the specific error related to the macro.

    /Jan

  • IanS 22 posts 65 karma points
    Feb 23, 2015 @ 17:56
    IanS
    0

    Using MVC. The more detailed message from the logs is the 2nd one shown above.

    Thanks

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Feb 23, 2015 @ 18:18
    Dennis Aaen
    0

    Hi IanS,

    Is there a specific reason why you need to use a partial view macro in the RTE to show a YouTube video, instead of you use the built in embed function in the RTE. It can take YouTube videos.

    Hope this helps,

    /Dennis

     

  • IanS 22 posts 65 karma points
    Feb 23, 2015 @ 18:24
    IanS
    0

    Hi Dennis

    One reason is I want to wrap the iframe embed code with a parent tag that makes the player responsive and fixes some formatting. Also, the built in embed insists on a width and height which I don't want.

    Either way, it would be nice to know why it isn't working.   I found a bug report of something that is fairly similar: http://issues.umbraco.org/issue/U4-3789

     

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Feb 23, 2015 @ 18:31
    Dennis Aaen
    0

    Hi IanS,

    Okay that make sense, try to see this thread about the same topic perhaps you can use the same approach as Chris. https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/61268-Umbraco-Grid-editor,-YouTube,-and-Bootstrap

    Hope this helps,

    /Dennis

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Feb 23, 2015 @ 18:34
    Jan Skovgaard
    0

    Hi Ian

    Ah, sorry missed that - Looked like the error one usually get's when seeing the error in the browser.

    So you should probably just check if there has been set a value before trying to render the iframe code.

    /Jan

  • IanS 22 posts 65 karma points
    Feb 24, 2015 @ 11:34
    IanS
    0

    Thanks Dennis.  The approach Chris is using is the same as mine though.

    I have since discovered that when i add the macro to the RTE, if I check the network panel in firefox I can see umbraco trying to hit the following URL but it is getting a 404 (not found) back:

    /umbraco/backoffice/UmbracoApi/Macro/GetMacroResultAsHtmlForEditor?macroAlias=YouTubevideo&pageId=-1&macroParams%5B0%5D.key=videoID&macroParams%5B0%5D.value=1234567

    Should this page exist? I can't find it in my installation although it is referenced in these scripts:

    \umbraco\Js\umbraco.resources.js

    umbraco\Js\umbraco.services.js

     

  • IanS 22 posts 65 karma points
    Feb 24, 2015 @ 11:39
  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Feb 24, 2015 @ 11:40
    Dennis Aaen
    0

    Hi IanS,

    I just think that your partial view macro file, just need to contain this snippet of code.

    inheritsUmbraco.Web.Macros.PartialViewMacroPage

    @if(Model.MacroParameters["
    videoID"]! =null)
    {
     
    var fullLink = Model.MacroParameters["
    videoID"].ToString();
     
    var youTubeId = fullLink.Split('=').Last();

     
    <div class="embed-responsive embed-responsive-16by9">
       
    <iframe class="embed-responsive-item" type="text/html" src="http://www.youtube.com/embed/@youTubeId?rel=0&showinfo=0" allowfullscreen="true"></iframe>
      </
    div>
    }

    Hope this helps,

    /Dennis

  • IanS 22 posts 65 karma points
    Feb 24, 2015 @ 11:44
    IanS
    0

    Thanks again. Have just tried that but unfortunately still getting the 404 error

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Feb 24, 2015 @ 12:09
    Dennis Aaen
    0

    Hi IanS,

    I have no problem to get this to work on the frontend of the website with this code snippet. I have added the macro paramter called videoID, as type textbox.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @if (Model.MacroParameters["videoID"] != null){
        
        var fullLink = Model.MacroParameters["videoID"].ToString();
          var youTubeId = fullLink.Split('=').Last();
       
        <div class="embed-responsive embed-responsive-16by9">
          <iframe class="embed-responsive-item" type="text/html" src="http://www.youtube.com/embed/@youTubeId?rel=0&showinfo=0" allowfullscreen="true"></iframe>
       
        </div>
    }

    But in the backend i will just get this macro Alias: YouTube in a yellow dotted box. Did you remember to add the parameter to the macro, and make sure that the alias is videoID. casing is very important herre.

    Hope this helps,

    /Dennis

  • IanS 22 posts 65 karma points
    Feb 24, 2015 @ 12:17
    IanS
    0

    Hi Dennis.

    Yes I've added the parameter to the macro with the alias in the correct case and set as a textbox field.  The 404 error I get is:

    The url returned a 404 (not found) for /umbraco/backoffice/UmbracoApi/Macro/GetMacroResultAsHtmlForEditor

    This file doesn't exist for me.  Should it?  If not, there must be some custom routing.

  • IanS 22 posts 65 karma points
    Feb 25, 2015 @ 16:58
    IanS
    0

    I've tried the latest build of Umbraco and this is still happening.  Must be a bug then.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies