Пример #1
0
        /// <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")));
        }
Пример #2
0
 private static void CheckInitialized(this IExtendibleTemplate template)
 {
     if (template.Package == null || template.Engine == null)
     {
         throw new InvalidOperationException("This method can not be invoked, unless Initialize has been called");
     }
 }
Пример #3
0
        /// <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);
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
 /// <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));
 }
Пример #6
0
 /// <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);
 }
Пример #7
0
 public static bool IsPublishing(this IExtendibleTemplate template)
 {
     template.CheckInitialized();
     return(template.Engine.RenderMode == RenderMode.Publish);
 }
Пример #8
0
 /// <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);
 }