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?
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; } } }
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; } } }
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.
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
Did you try to add the values with the Standard Values package? I think that should also work.
Jeroen
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:
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
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.
is working on a reply...