Copied to clipboard

Flag this post as spam?

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


  • Rasmus Lynggaard 118 posts 325 karma points
    Nov 07, 2011 @ 17:47
    Rasmus Lynggaard
    0

    Programmatically add macros to macrocontainer

    Hi all

    I'm using the macrocontainer for side widgets - which it's great for - but I would like to add a few macros as default selected. My thought was to add them during the Document_BeforeSave event, but I've run into a problem. I don't know how to add the macros programmatically. Do you? Or can you lead me in a direction?

     

    /Rasmus

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Nov 07, 2011 @ 18:18
    Jeroen Breuer
    0

    Did you try to add the values with the Standard Values package? I think that should also work.

    Jeroen

  • Rasmus Lynggaard 118 posts 325 karma points
    Nov 07, 2011 @ 18:25
    Rasmus Lynggaard
    0

    No, I haven't. I'm not so trilled of the standard values package. Seen it cause more troubles than good.

    Further I'm going to add different default macros, depending on the document type. Like this:

    void Document_BeforeSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
    {
    if (!sender.HasPublishedVersion())
    {
    switch (sender.ContentType.Alias) {
    case "Article":
    //Add some macros to the macrocontainer
    break;
    case "NewsItem":
    //Add some other macros to the macro container
    break;
    }
    }
  • Rasmus Lynggaard 118 posts 325 karma points
    Nov 08, 2011 @ 10:39
    Rasmus Lynggaard
    0

    Ok, it actually turned out to be pretty straightforward. I just looked at the XML output and tried to give that to the values. Like this

    voidDocument_BeforeSave(Document sender, umbraco.cms.businesslogic.SaveEventArgs e)
    {
     
    if(!sender.HasPublishedVersion())
     
    {
       
    switch(sender.ContentType.Alias)
       
    {
         
    case"Article":
           
    //Add some macros to the macrocontainer
    if (sender.getProperty("sidebar") != null)
    sender.getProperty("sidebar").Value = "<?UMBRACO_MACRO macroalias=\"Contact\" />";
           
    break;
         
    case"NewsItem":
           
    //Add some other macros to the macro container
           
    break;
       
    }
     
    }
    }
  • Eduardo Sobrinho 18 posts 38 karma points
    Sep 16, 2016 @ 17:10
    Eduardo Sobrinho
    0

    Rasmus I have a similar problem. I need to dynamically create macros with parameter fields. You know how to do this?

    My goal is very simple. When I upgrade versions using Visual Studio, generate application packages that I import from IIS on the site. All routines and cshtml files are published, however, the macro does not is createda in macroconteiner. So I have to create them one by one in each website.

Please Sign in or register to post replies

Write your reply to:

Draft