Copied to clipboard

Flag this post as spam?

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


  • Frederik T 242 posts 373 karma points
    Sep 29, 2011 @ 17:23
    Frederik T
    0

    Very quick question

    In a template, i have this

    <umbraco:Macro RedirOnLogin="/pro/ansoeg" ShowFacebook="0" ShowLinkedIn="1" Alias="LoginForm" runat="server"></umbraco:Macro>

    When that template is shown, a value is passed in the url that other macro's use with [@valueNameHere]

    I want to pass that with the macro, and that can be done like so:

    <umbraco:Macro RedirOnLogin="[@id]" ShowFacebook="0" ShowLinkedIn="1" Alias="LoginForm" runat="server"></umbraco:Macro>

    Which works, but i want to combine them like this:

    <umbraco:Macro RedirOnLogin="/pro/ansoeg?id=[@id]" ShowFacebook="0" ShowLinkedIn="1" Alias="LoginForm" runat="server"></umbraco:Macro>

    But that doesnt work. Any suggestions?

  • Rodion Novoselov 694 posts 859 karma points
    Sep 29, 2011 @ 17:38
    Rodion Novoselov
    0

    As a very quick solution I would just split the 'RedirOnLogin' parameter to a couple and then concatenate them inside the macro.

  • Frederik T 242 posts 373 karma points
    Oct 06, 2011 @ 13:36
    Frederik T
    0

    Thank you for your reply. I was hoping if that wasnt necessary as it would be a lot of work. The macro is a usercontrol and thats another team working on them, not to mention the same macro is used other places.

    Oh well, but if its impossible i will try and propose Rodion's solution.

  • Rodion Novoselov 694 posts 859 karma points
    Oct 06, 2011 @ 15:10
    Rodion Novoselov
    0

    Hi again. I can suggest some trick that looks like a bit of a hack and I cannot be absolutely sure that it will work in your case, but I used it one day in the past for some other purposes and it worked for me that time.

    So, well, if you look into the source code of the 'Macro' control there's a piece in the very beginning of the 'CreateChildControls' that reads:

     

            protected override void CreateChildControls() {
    // collect all attributes set on the control
                var keys = Attributes.Keys;
                foreach (string key in keys)
                    MacroAttributes.Add(key.ToLower(), Attributes[key]);

     

    Since the method is virtual you can simply inherit your own control from Macro and override this method:

     

    public class MyMacro: Macro
    {
        protected override void CreateChildControl()
        {
            // In this place the 'Attributes' collection contains
    // the macro's parameter among other attributes
            // and since that you can modify them the way you want

             // and then, the base class's method will be called with modified attributes
             base.CreateChildControl();
        }
    }

     

    Then you compile your class and register them as a usual custom control and then you can use it istead of the stadard umbraco:Macro where you want.

    With this method you won't need to modify any way the macro or underlying user contro themselves since you play around only with the Macro control that's in fact is just a wrapper by which the macro placed into a page.

Please Sign in or register to post replies

Write your reply to:

Draft