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

Forums / Developing with Sitefinity / Custom Content

Custom Content

4 posts, 0 answered
  1. Todd
    Todd avatar
    8 posts
    Registered:
    14 Aug 2007
    22 Aug 2007
    Link to this post
    With in our web site we have several pages that need the display different content base on a variable passed within a query string.  I am wonder what the best approach would be. 

    I could create multiple pages with the custom content but is it possible to redirect to other pages base on querystrings or should this be done in a custom user control?

    I am open to any solutions

    Thanks

    Todd
  2. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    23 Aug 2007
    Link to this post
    Hi Todd,

    Yes, you would have to do it in a user control. In the code there you can check the querystring, and either redirect to different pages or just stay on the current page and display different content. I think the second option is better.
    If you are using generic content, you can pass the ID in the QueryString and then use the GetContent() method of the ContentManager class to get the content, passing the ID as parameter. This class is in the Telerik.Cms.Engine namespace.

    Sincerely yours,
    Slavo
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Todd
    Todd avatar
    8 posts
    Registered:
    14 Aug 2007
    23 Aug 2007
    Link to this post
    Without looking in database table sf_CmsTextContent, is there a way to determine what the id of the generic content is?  Is there a method to retrieve the ContentID by the name of the generic content. 

    I also noticed that a user can enter the same Name for multiple Generic Content pages.    I would've thought that the Name of the Generic Content pages would be unique so an overloaded method could've been used to retrieve content base on the name.

    Todd
  4. Slavo
    Slavo avatar
    295 posts
    Registered:
    24 Sep 2012
    24 Aug 2007
    Link to this post
    Hello Todd,

    In this post, when I say content Name, I mean Title, it is the same.

    The content items in Sitefinity are differentiated by ID, not Name, so it is possible to create multiple content items with the same name. The name is considered as metadata for the content itself. Here is how you can retrieve content items by name:

    First, create an instance of the ContentManager class. It has a method GetContent() which has 12 overloads depending on how you wish to search for content. One of these overloads takes a IMetaSearchInfo object as a parameter, this is the one you need. Create an instance of the MetaSearchInfo class, which implements the IMetaSearchInfo interface. The constructor of this class takes three values as parameters - the type of metadata, the key of the metadata and the value to search for. In your case, the type of metadata should be ShortText, this is how the Name of the content is stored. Then the key should be "Name", and the value should be a string, containing the name of the content you want to retrieve. This is the code itself:

    ContentManager manager = new ContentManager();  
    MetaSearchInfo info = new MetaSearchInfo(MetaValueTypes.ShortText, "Name""Content1");  
            IList foundContent = manager.GetContent(info);  
    Guid contentID = (foundContent[0] as IContent).ID; 

    Note that the GetContent() method returns a list of content items, not a single one, so you need to access the first in the list. Now, if you substitute "Content1" with the name of the content, which you pass in the query string, you would be able to get the ID of the content with that name. Just make sure that you are passing a valid name in the query string.
    I hope this makes it clearer.

    Greetings,
    Slavo
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
4 posts, 0 answered