How to determine if an EPiServer Composer function is placed in another Composer function

by Andreas Nylin 9. November 2009 09:56

Sometimes it can be handy to know if a Composer function is placed directly on the page or if it's placed in another Composer function. Here is a piece of code I wrote that does the trick.
The property must be placed in a class that derives from Dropit.Extension.Core.BaseContentFunction

 

private bool ParentIsContentFunction
{
    get
    {
        // Make sure that the current page is an Composer page
        if (this.CurrentExtensionPageData != null)
        {
            ContentFunctionData currentContentFunctionData = new ContentFunctionData(this.ContentFunctionLink);
            
            // Loop through all content areas in the page
            foreach(ContentAreaData ca in this.CurrentExtensionPageData.ContentAreas)
            {    
                // If any of the content areas contains the current content function it means that the function is placed directly on the page
                // - it's not placed in another content function
                if (ca.ContentFunctions.Contains(currentContentFunctionData))
                    return false;
            }
        }
        
        // If we reach this code it means that the content function is placed in another content function
        return true;
    }
}

Tags: , ,

Development

blog comments powered by Disqus

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 2.5 Sweden License.


Welcome to the Dropit blog!

Here we, the people that work at Dropit, will write about stuff that interests us. For example web development, especially with .NET and EPiServer - but we'll also talk about other techniques that interest us, marketing on the web, social phenomenons, pop culture, games and software development in general.