예제 #1
0
 protected string GetUrl(Page page)
 {
     string url;
     if (page.PageTemplate.Title.Equals(_config.ExternalUrlTemplate, StringComparison.InvariantCultureIgnoreCase) && page.Metadata != null)
     {
         // The Page is a "Redirect Page"; obtain the URL from its metadata.
         ItemFields meta = new ItemFields(page.Metadata, page.MetadataSchema);
         ItemFields link = meta.GetEmbeddedField("redirect");
         url = link.GetExternalLink("externalLink");
         if (string.IsNullOrEmpty(url))
         {
             url = link.GetSingleFieldValue("internalLink");
         }
     }
     else
     {
         url = GetExtensionlessUrl(page.PublishLocationUrl);
     }
     return url;
 }
        protected string GetUrl(Page page)
        {
            string url;

            if (page.PageTemplate.Title.Equals(_config.ExternalUrlTemplate, StringComparison.InvariantCultureIgnoreCase) && page.Metadata != null)
            {
                // The Page is a "Redirect Page"; obtain the URL from its metadata.
                ItemFields meta = new ItemFields(page.Metadata, page.MetadataSchema);
                ItemFields link = meta.GetEmbeddedField("redirect");
                url = link.GetExternalLink("externalLink");
                if (string.IsNullOrEmpty(url))
                {
                    url = link.GetSingleFieldValue("internalLink");
                }
            }
            else
            {
                url = GetExtensionlessUrl(page.PublishLocationUrl);
            }
            return(url);
        }
        private string GetNavigationTitleFromComp(Component mainComp)
        {
            //TODO, make the field names used to extract the title configurable as TBB parameters
            string title = null;

            if (mainComp != null)
            {
                if (mainComp.Metadata != null)
                {
                    ItemFields meta      = new ItemFields(mainComp.Metadata, mainComp.MetadataSchema);
                    ItemFields embedMeta = meta.GetEmbeddedField("standardMeta");
                    if (embedMeta != null)
                    {
                        title = embedMeta.GetTextValue("name");
                    }
                }
                if (String.IsNullOrEmpty(title))
                {
                    ItemFields content = new ItemFields(mainComp.Content, mainComp.Schema);
                    title = content.GetTextValue("headline");
                }
            }
            return(title);
        }
 private string GetNavigationTitleFromComp(Component mainComp)
 {
     //TODO, make the field names used to extract the title configurable as TBB parameters
     string title = null;
     if (mainComp != null)
     {
         if (mainComp.Metadata != null)
         {
             ItemFields meta = new ItemFields(mainComp.Metadata, mainComp.MetadataSchema);
             ItemFields embedMeta = meta.GetEmbeddedField("standardMeta");
             if (embedMeta != null)
             {
                 title = embedMeta.GetTextValue("name");
             }
         }
         if (String.IsNullOrEmpty(title))
         {
             ItemFields content = new ItemFields(mainComp.Content, mainComp.Schema);
             title = content.GetTextValue("headline");
         }
     }
     return title;
 }
예제 #5
0
        protected override string Render()
        {
            // Each ItemField derived type has the .HasValue() extension method
            // that can be used to check whether such field has a value.

            ItemFields fields = this.Model.GetFields();

            /* *******************************************************************************
            * TextField, XhtmlField, SingleLineTextField, MultiLineTextField, ExternalLinkField
            * ***************************************************************************** */

            bool hasValue = fields.GetField <TextField>("name").HasValue();

            // Alternatives.

            hasValue = fields.GetTexts("name").Count > 0;
            hasValue = fields.GetText("name") != null;

            /* *******************************************************************************
            * ComponentLinkField, MultimediaLinkField
            * ***************************************************************************** */

            hasValue = fields.GetField <ComponentLinkField>("link").HasValue();

            // Alternatives.

            hasValue = fields.GetComponents("link").Count > 0;
            hasValue = fields.GetComponent("link") != null;

            /* *******************************************************************************
            * EmbeddedSchemaField.
            * ***************************************************************************** */

            hasValue = fields.GetField <EmbeddedSchemaField>("paragraphs").HasValue();

            // Alternatives.

            hasValue = fields.GetEmbeddedFields("paragraphs").Count > 0;
            hasValue = fields.GetEmbeddedField("paragraphs") != null;

            /* *******************************************************************************
            * Accessing DateField.
            * ***************************************************************************** */

            hasValue = fields.GetField <DateField>("publish_date").HasValue();

            // Alternatives.

            hasValue = fields.GetDates("publish_date").Count > 0;
            hasValue = fields.GetDate("publish_date") != DateTime.MinValue;

            /* *******************************************************************************
            * NumberField.
            * ***************************************************************************** */

            hasValue = fields.GetField <NumberField>("age").HasValue();

            // Alternatives.

            hasValue = fields.GetNumbers("age").Count > 0;
            hasValue = fields.GetNumber("age") != double.MinValue;

            /* *******************************************************************************
            * Accessing KeywordField.
            * ***************************************************************************** */

            hasValue = fields.GetField <KeywordField>("tag").HasValue();

            // Alternatives.

            hasValue = fields.GetKeywords("tag").Count > 0;
            hasValue = fields.GetKeyword("tag") != null;

            return(string.Empty);
        }
예제 #6
0
        protected override string Render()
        {
            // Model is a Component.

            // Get ItemFields from Component. Then access individual fields from the ItemFields object.

            ItemFields fields = this.Model.GetFields();

            // Alternatively, it's possible to access individual fields directly from a
            // Component. This is made possible for cases in which only one field is needed
            // from a Component.

            // In case you need to access more than one fields from a Component you should
            // get the ItemFields (as above) then access the individual fields from the
            // ItemFields object. This will make your code to execute faster.

            string title = this.Model.GetText("title");

            // Below are sample codes for accessing different ItemField types from ItemFields.

            /* *******************************************************************************
            * Accessing TextField, XhtmlField, SingleLineTextField, MultiLineTextField, ExternalLinkField
            * ***************************************************************************** */

            // IMPORTANT NOTE: when a handler for the TridionExtensions.XhtmlResolver delegate
            // is assigned .GetText() will automatically resolve xhtml content from an XhtmlField.
            // See IntranetController how the TridionExtensions.XhtmlResolver is assigned.

            string         text  = fields.GetText("text");
            IList <string> texts = fields.GetTexts("texts");

            text  = fields.GetField <TextField>("text").Value;
            texts = fields.GetField <TextField>("texts").Values;

            /* *******************************************************************************
            * Accessing ComponentLinkField, MultimediaLinkField
            * ***************************************************************************** */

            Component         component  = fields.GetComponent("link");
            IList <Component> components = fields.GetComponents("links");

            // Alternatives.

            component  = fields.GetField <ComponentLinkField>("link").Value;
            components = fields.GetField <ComponentLinkField>("links").Values;

            /* *******************************************************************************
            * Accessing EmbeddedSchemaField.
            * ***************************************************************************** */

            ItemFields         embeddedField  = fields.GetEmbeddedField("paragraphs");
            IList <ItemFields> embeddedFields = fields.GetEmbeddedFields("paragraphs");

            // Alternatives.

            embeddedField  = fields.GetField <EmbeddedSchemaField>("paragraphs").Value;
            embeddedFields = fields.GetField <EmbeddedSchemaField>("paragraphs").Values;

            /* *******************************************************************************
            * Accessing DateField.
            * ***************************************************************************** */

            DateTime         publishDate  = fields.GetDate("publish_date");
            IList <DateTime> publishDates = fields.GetDates("pubish_date");

            // Alternatives.

            publishDate  = fields.GetField <DateField>("publish_date").Value;
            publishDates = fields.GetField <DateField>("publish_date").Values;

            /* *******************************************************************************
            * Accessing NumberField.
            * ***************************************************************************** */

            double         height  = fields.GetNumber("height");
            IList <double> heights = fields.GetNumbers("height");

            // Alternatives.

            height  = fields.GetField <NumberField>("height").Value;
            heights = fields.GetField <NumberField>("height").Values;

            /* *******************************************************************************
            * Accessing KeywordField.
            * ***************************************************************************** */

            Keyword         tag  = fields.GetKeyword("tag");
            IList <Keyword> tags = fields.GetKeywords("tag");

            // Alternatives.

            tag  = fields.GetField <KeywordField>("tag").Value;
            tags = fields.GetField <KeywordField>("tag").Values;

            return(string.Empty);
        }
예제 #7
0
 protected string GetUrl(Page page)
 {
     String url = page.PublishLocationUrl;
     if (_config.ExternalUrlTemplate.ToLower() == page.PageTemplate.Title.ToLower() && page.Metadata != null)
     {
         var meta = new ItemFields(page.Metadata,page.MetadataSchema);
         var link = meta.GetEmbeddedField("redirect");
         url = link.GetExternalLink("externalLink");
         if (String.IsNullOrEmpty(url))
         {
             url = link.GetSingleFieldValue("internalLink");
         }
     }
     return System.Web.HttpUtility.UrlDecode(url);
 }