/// <summary>
        /// Returns the page object that is defined in the package for this template.
        /// </summary>
        /// <remarks>
        /// This method should only be called when there is an actual Page item in the package. 
        /// It does not currently handle the situation where no such item is available.
        /// </remarks>
        /// <returns>the page object that is defined in the package for this template.</returns>
        public static Page GetPage(this IExtendibleTemplate template)
        {
            template.CheckInitialized();

            Item pageItem = template.Package.GetByType(ContentType.Page);
            if (pageItem != null)
            {
                return template.Engine.GetObject(pageItem.GetAsSource().GetValue("ID")) as Page;
            }

            Page page = template.Engine.PublishingContext.RenderContext.ContextItem as Page;
            return page;
        }
        /// <summary>
        /// Returns the publication object that can be determined from the package for this template.
        /// </summary>
        /// <remarks>
        /// This method currently depends on a Page item being available in the package, meaning that
        /// it will only work when invoked from a Page Template.
        /// 
        /// Updated by Kah Tan ([email protected])
        /// </remarks>
        /// <returns>the Publication object that can be determined from the package for this template.</returns>
        public static Publication GetPublication(this IExtendibleTemplate template)
        {
            template.CheckInitialized();

            RepositoryLocalObject pubItem = null;
            Repository repository = null;

            if (template.Package.GetByType(ContentType.Page) != null)
                pubItem = template.GetPage();
            else
                pubItem = template.GetComponent();

            if (pubItem != null) repository = pubItem.ContextRepository;

            return repository as Publication;
        }
 /// <summary>
 /// Returns the component object that is defined in the package for this template.
 /// </summary>
 /// <remarks>
 /// This method should only be called when there is an actual Component item in the package. 
 /// It does not currently handle the situation where no such item is available.
 /// </remarks>
 /// <returns>the component object that is defined in the package for this template.</returns>
 public static Component GetComponent(this IExtendibleTemplate template)
 {
     template.CheckInitialized();
     Item component = template.Package.GetByType(ContentType.Component);
     return (Component)template.Engine.GetObject(component.GetAsSource().GetValue("ID"));
 }
 /// <summary>
 /// Creates a new text item in the package
 /// </summary>
 /// <param name="name">The name of the text item to create in the package </param>
 /// <param name="value">The value of the text item to create in the package</param>
 public static void CreateTextItem(this IExtendibleTemplate template, string name, string value)
 {
     template.CheckInitialized();
     template.CreateStringItem(name, value, ContentType.Text);
 }
 /// <summary>
 /// creates a new String item in the package with the specified ContentType
 /// </summary>
 /// <param name="name">The name of the text item to create in the package </param>
 /// <param name="value">The value of the text item to create in the package</param>
 /// <param name="type">The Type of the item to create, for instance: text, html, xml, etc.</param>
 public static void CreateStringItem(this IExtendibleTemplate template, string name, string value, ContentType type)
 {
     template.CheckInitialized();
     template.Package.PushItem(name, template.Package.CreateStringItem(type, value));
 }
 public static bool IsPublishing(this IExtendibleTemplate template)
 {
     template.CheckInitialized();
     return (template.Engine.RenderMode == RenderMode.Publish);
 }
 /// <summary>
 /// True if the rendering context is a page, rather than component
 /// </summary>
 public static bool IsPageTemplate(this IExtendibleTemplate template)
 {
     template.CheckInitialized();
     return template.Engine.PublishingContext.ResolvedItem.Item is Page;
 }