1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Displaying a generic content item with external template

Displaying a generic content item with external template

2 posts, 0 answered
  1. Larry
    Larry avatar
    1 posts
    Registered:
    18 Sep 2009
    15 Dec 2009
    Link to this post
    Hello - I am looking for a way to have a user select a single generic content item to display on the page and have that item call a template to display only the title and other information defined in the metafields for that content.

    I am struggling with how to do this using a custom user control based on either the generic content control or the content view control.

    Can someone help point me in the right direction?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    15 Dec 2009
    Link to this post
    Hello Kevin Colletti,

     You have to create a custom control that derives to ContentView class or some of the other ContentView based controls. Then you need to map the external template that you are going to use using SingleItemTemplatePath and ItemListTemplatePath properties of the control. You can just implement a simple selector to the control ( here is  a sample Creating a custom WebUITypeEditor  and set its value as SelectedItemId property of ContentView ( the member is marked as obolete, but it works withouth problems for now)

    Generally you can use GenericContent control which has a selector from where you can add the content of the shared GenericConent objects.  the default control does not show the metadata, so you can extend the default contorl and add several textboxes to its designer which will be populated with the metadata of a single item.

    Steps

    1. Create a custom class tha derives from GeneriContent

    2. Implement a TooboxItem for your custom class.

    3. Implement a custom Designer that inherits from GenericContentDesigner

    sample:

    custom class that inherits from GenericContent

    [ToolboxItem(typeof(GenericContentToolBoxItemCustom))]
    [ControlDesigner(typeof(GenericContentCustomDesigner))]
    public class GenericContentCustom : GenericContent
    {
     
    }

    Toolbox item

    public class GenericContentToolBoxItemCustom : ToolboxItem
    {
        
        public GenericContentToolBoxItemCustom ()
            : base(typeof(GenericContentCustom))
        {
            base.DisplayName = "some name";
            base.Description = "some desc";
        }
    }

    designer


    public
    class GenericContentCustomDesigner : GenericContentDesigner
    {
      //
    }

    In the designer template you need to create several texbox controls which Text property will be set to the selected IContent object metadata. Then in Render method ( Called to write the actual html for this control )
    of your custom GenericContent you need to write the same values.

    Sincerely yours,
    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.
2 posts, 0 answered