More in this section

Forums / Developing with Sitefinity / Change default value for meta field

Change default value for meta field

4 posts, 0 answered
  1. Florian
    Florian avatar
    17 posts
    Registered:
    08 Aug 2008
    04 Nov 2009
    Link to this post
    Hi

    Excuse me, if I'v overseen a matching answer for my question in the forum.

    I want to change the following default values (for every new gallery the user put into a page):

    - The selected library ("1. Which images to display"), at the moment it's set to "Images from all image galleries"
    - The display-type to "List & Lightbox"
    - The Advanced/Filters/SortExpression to "Name ASC"

    I tried to add the meta fields to the web.config, but this doesn't work. I think these values are hardcoded somewhere. Is it possible to change them?

    Thanks a lot for a response.

    Cheers

    Florian Dürrbaum
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Nov 2009
    Link to this post
    Hello Florian,

    1. You should create a custom control that derives from ImageGallery and create a control designer for it.
     
     - The selected library ("1. Which images to display"), at the moment it's set to "Images from all image galleries"

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Libraries.WebControls;
    using Telerik.Framework.Web.Design;
     
    /// <summary>
    /// Summary description for CustomImageGallery
    /// </summary>
    ///
    [ControlDesignerAttribute("ImageGalleryDesignerCustom, App_Code")]
    public class CustomImageGallery : ImageGallery
    {
        public CustomImageGallery()
        {
     
        }
                 // DO this in case you want to set the mode programmatically so that it will be Lightbox only
        public override string ItemListTemplatePath
        {
            get
            {
                return "~/Sitefinity/Admin/ControlTemplates/Libraries/Modes/GalleryLightboxList.ascx";
            }
             
        }
        protected override void CreateChildControls()
        {
               // DO this only of you want to use Lightbox mode only
            this.GalleryTemplateMode = ImageGallery.GalleryViewMode.Lightbox;
            this.BehaviorMode = Telerik.Cms.Engine.WebControls.ContentView.BehaviorModes.Master;
            base.CreateChildControls();
        }
    }

    In the custom designer override SetGallerySelector and set the selected library.

    public class ImageGalleryDesignerCustom : ImageGalleryDesigner
    {
        public ImageGalleryDesignerCustom()
        {
        }
     
        public override string DesignerTemplatePath
        {
            get
            {
                return "~/Sitefinity/Admin/ControlTemplates/Libraries/ImageGalleryControlDesigner.ascx";
            }
        }
     
        protected override void SetGallerySelector()
        {
            base.SetGallerySelector();
            GallerySelector gallerySelector = ItemContainer.FindCustomSelector<GallerySelector>("GuidSelector");
            if (gallerySelector != null)
            {
                gallerySelector.SelectedValues = new List<Guid>() { new Guid("B001E685-826B-4643-8A39-DD99D4026E96") };
                gallerySelector.ProviderName = Component.ProviderName;
         
            }
        }
    }


     - The display-type to "List & Lightbox"

    The easiest way to achieve this is replacing the position of ListDetails and List & Lightbox modes in the ControlDesigner templates

    <sf:PresentationModes ID="presentationModes" runat="server">
     <sf:PresentationMode ID="Lightbox"
                                                 runat="server"
                                                 ModeTitle="List & Lightbox"
                                                 ModeSettingsId="ModeSettings2"
                                                 MasterTemplateName="Telerik.Libraries.Resources.ControlTemplates.Frontend.GalleryLightboxList.ascx"
                                                 SelectedCssClass="selectedOption">
                                <Template>
                                    <asp:RadioButton ID="lightboxRadio" runat="server" />
                                    <p><asp:Literal ID="Literal2" runat="server" Text="<%$Resources:GalleryDesigner_Lightbox %>" /></p>
                                </Template>
                            </sf:PresentationMode>                       
     
     
    <sf:PresentationMode ID="ListDetails"
                                                 runat="server"
                                                 ModeTitle="List & page"
                                                 ModeSettingsId="ModeSettings1"
                                                 MasterTemplateName="Telerik.Libraries.Resources.ControlTemplates.Frontend.GalleryListView.ascx"
                                                 DetailTemplateName="Telerik.Libraries.Resources.ControlTemplates.Frontend.GalleryListViewItem.ascx"
                                                 SelectedCssClass="selectedOption">
                                <Template>
                                    <asp:RadioButton ID="listPageRadio" runat="server" />
                                    <p><asp:Literal ID="Literal1" runat="server" Text="<%$Resources:GalleryDesigner_ListDetailsView %>" /></p>
                                </Template>
                            </sf:PresentationMode>
                            
                            <sf:PresentationMode ID="SimpleOnePerPage"
                                                 runat="server"
                                                 ModeTitle="One per page"
                                                 ModeSettingsId="ModeSettings3"
                                                 MasterTemplateName="Telerik.Libraries.Resources.ControlTemplates.Frontend.GalleryOnePerPageList.ascx"
                                                 SelectedCssClass="selectedOption">
                                <Template>
                                    <asp:RadioButton ID="simpleOnePerPageRadio" runat="server" />
                                    <p><asp:Literal ID="Literal3" runat="server" Text="<%$Resources:GalleryDesigner_SimpleOnePerPage %>" /></p>
                                </Template>
                            </sf:PresentationMode>
                            <sf:PresentationMode ID="Simple"
                                                 runat="server"
                                                 ModeTitle="Simple list"
                                                 ModeSettingsId="ModeSettings4"
                                                 MasterTemplateName="Telerik.Libraries.Resources.ControlTemplates.Frontend.GallerySimpleList.ascx"
                                                 SelectedCssClass="selectedOption">
                                <Template>
                                    <asp:RadioButton ID="simpleRadio" runat="server" />
                                    <p><asp:Literal ID="Literal4" runat="server" Text="<%$Resources:GalleryDesigner_Simple %>" /></p>
                                </Template>
                            </sf:PresentationMode>
                            <sf:PresentationMode ID="BigImageAndList"
                                                 runat="server"
                                                 ModeTitle="Image & List"
                                                 ModeSettingsId="ModeSettings5"
                                                 MasterTemplateName="Telerik.Libraries.Resources.ControlTemplates.Frontend.GalleryBigImageAndList.ascx"
                                                 SelectedCssClass="selectedOption">
                                <Template>
                                    <asp:RadioButton ID="bigImageAndListRadio" runat="server" />
                                    <p><asp:Literal ID="Literal26" runat="server" Text="<%$Resources:GalleryDesigner_BigImageAndList %>" /></p>
                                </Template>
                            </sf:PresentationMode>
                    </sf:PresentationModes>

    In CustomImageGallery override the property below to return the desired expression.

    public override string SortExpression
    {
        get
        {
            string s = (string)this.ViewState["SortExpression"];
            if(string.IsNullOrEmpty(s))
                return "Name ASC";
                    return s;
        }
        set
        {
            this.ViewState["SortExpression"] = value;
        }
             
    }

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Florian
    Florian avatar
    17 posts
    Registered:
    08 Aug 2008
    09 Nov 2009
    Link to this post
    Hi Ivan

    Thanks a lot, it worked.

    I had to add following condition, otherwise the selected gallery had been reseted after opening the designer dialog:

        protected override void SetGallerySelector() 
        { 
            // ... 
            if (gallerySelector != null && gallerySelector.SelectedValues.Count == 0) 
            { 
              // .... 
            } 
        } 

    Further I had to update the project to Sf version 3.7: I am a little bit confused about the strategy for changing templates, using the external project templates. In 3.6 (nearly) every template could have been changed by adding the mapping to the Telerik.Sitefinity.Configuration.ControlsConfig.xml. Now it's seems to be more usual to create a deriving custom control and overwrite the XXXTemplatePath method. What strategy does Telerik recommend?

    Thanks and cheers,

    Florian
  4. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    10 Nov 2009
    Link to this post
    Hi Florian,

    Well most controls work with the controls config file, however we do experience some troubles with cotnrols such as the Image Gallery (not implemented view settings for it yet) or the Blog Posts, where you would either use your approach or set the paths to the external templates through the UI control editor.

    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered