Knowledge Base

Looking Back at 2023 Software Release Highlights: Custom Macros

Custom macros are a new feature in Ingeniux CMS 10.6 that extends the functionality of custom hooks to allow manual triggering of a script. These scripts can automate functions in the CMS, such as creating or archiving content, updating outside data sources, or auditing administration and security.


A new year is upon us. What better time to take stock of what we achieved in the previous one? The release of Ingeniux CMS 10.6 was a major milestone for the Ingeniux platform. It introduced a number of new features and enhancements in the platform, including custom macros.  

Custom macros are a new feature in Ingeniux CMS 10.6 that extends the functionality of custom hooks to allow manual triggering of a script. These scripts can automate functions in the CMS, such as creating or archiving content, updating outside data sources, or auditing administration and security. 

What’s New? 

In earlier releases, custom hooks exclusively triggered scripts when a user initiated specific actions, like page check-ins or user creation. While these scripts were valuable for extending functionality during those events, their use was confined to those specific triggers.  

 The addition of custom macros in CMS 10.6 offers administrators the freedom to employ these scripts as required, significantly expanding the CMS's capabilities with minimal developer effort. 

How It’s Used in the CMS 

The maintenance section of the CMS has a new section for displaying a list of custom macros that are available in the custom hooks file. These can be accessed at any time by an administrator and triggered as needed by the press of a button.  

IMAGE

Each custom macro is a script implemented by an engineer. They can perform any CMS task, or any task that might be necessary on a system the CMS could reach through most connection protocols. 

Digging Deeper 

Let’s dig a little deeper and take a look at an example of a custom macro in action.  

Custom Macro Example: Find and fill in all pages where users forgot to fill in a component 

In the following example, we’re going to set up a custom macro to find and fill in all pages where users forgot to fill in a component.  

This custom macro finds the first page named “Home” under x1 (the root of the whole CMS), locates the element on the page called “SectionControl” or “SiteControl”, and if those two items are not null proceeds to loop through the descendants of the home page and fill in any pages that also have an element called “SectionControl” or “SiteControl”,  with the same item that is used on the home page. 

Note that since we are starting with the session, we are immediately jumping into the Site object. This will be typical in your scripts, though you may also be interested in other areas such as schema, user, or workflow managers. 

As it processes, it checks to see if the pages are checked out before making the change. If they are not yet checked out, it checks them out and makes the change to the checked-out version of the page. 

 [CustomMacro("Section Controls", "Fill in all missing section controls with the same one as the home page.")] 

        public void SetEmptySectionControls(IUserWriteSession session) 

        { 

            var site = session.Site; 

            var siteRoot = site.Page("x1"); 

            int outVar; 

            var homePage = siteRoot.Descendants(out outVar).Where(p => p.Name == "Home").FirstOrDefault(); 

            if (homePage != null) 

            { 

                var controlComp = (homePage.Element("SectionControl") != null) ? homePage.Element("SectionControl") : homePage.Element("SiteControl"); 

                if (controlComp != null && controlComp.Value != "") 

                { 

                    var sitePages = homePage.Descendants(out outVar); 

                    foreach (var page in sitePages) 

                    { 

 

                        var pageControl = (page.Element("SectionControl") != null) ? page.Element("SectionControl") : page.Element("SiteControl"); 

                        if (pageControl != null && pageControl.Value == "") 

                        { 

                            if (!page.CheckedOut) 

                            { 

                                page.CheckOut(false); 

                            } 

                            pageControl.Value = controlComp.Value; 

                            page.Save(); 

                        } 

                    } 

                } 

            } 

        } 

You could easily extend or reshape this macro to update any field in your Site Tree based on similar logic by changing the variables for field name and the desired value to propagate. 

Impact on Users  

"Out-of-the-box" the new custom macros feature in CMS 10.6 doesn’t do anything – it will need to be set up and customized based on the unique requirements of the implementation.  

Only administrator-level users will have access to custom macros and will be able to configure them.  

Once properly set up and customized, this feature can be extremely powerful. Think about the time your users spend doing repetitive, predictive tasks: these can now be automated with custom macros. Ultimately, this feature can save an enormous amount of time and increase productivity. 

More Information and Resources 

For more in-depth information on this topic, check out some of the resources below. 

10.6 Release Information  

Tutorials 

Training Courses 

  • PRODUCT: CMS
  • VERSION: CMS 10
  • RELEASE: 10.6
  • Published: January 8, 2024
  • LAST UPDATED: September 25, 2024
  • Comments: 0

Please login to comment

Comments


There are no comments yet.