Copied to clipboard

Flag this post as spam?

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


  • david 2 posts 22 karma points
    May 11, 2012 @ 17:44
    david
    0

    Grab macro variable and pass it to doc type property using a template

     

    Hey everyone,

    I have a YouTube macro that takes a url and adjusts the url so that you get just the video, and I have a variable in the macro that has the new url.  I then have a banner doc type that has a link property which the user may enter a url, in the banner template I call the YouTube macro. I then want to take the variable inside the macro and set the link property with the new adjusted YouTube string.

    I apologize if this is in the wrong section.

    This is the template code:

    <asp:content ContentPlaceHolderId="ContentPlaceHolderDefault" runat="server">
      <umbraco:Macro Alias="Banner" runat="server"></umbraco:Macro>
      <umbraco:Macro youtubeUrl="[$currentPage/data[@alias='link.url']" Alias="Youtube" runat="server" >
      </umbraco:Macro>
    </asp:content>

    I dubbuged this through Visual Studio and I know it grabs the link properly.

    YouTube Macro:

    var youtubeVideoRegex = new Regex(@"youtu(?:\.be|be\.com)/(?:.*v(?:/|=)|(?:.*/)?)([a-zA-Z0-9-_]+)");

    Match youtubeMatch = youtubeVideoRegex.Match(@Parameter.youtubeUrl);

    string youtubeCode = youtubeMatch.Groups[1].Value;

    string url = "http://www.youtube.com/v/" + youtubeCode;

    The string variable 'url' is the one I would like to grab, I added it in hopes of being able to access it from outside the macro.

    Thanks!

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    May 13, 2012 @ 12:58
    Jeroen Breuer
    0

    I think this wiki can help you: http://our.umbraco.org/wiki/reference/templates/umbracomacro-element

    If you change your macro to this it should work:

    <umbraco:Macro youtubeUrl="[#link.url]" Alias="Youtube" runat="server" >

    Jeroen

  • 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