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

Forums / 3.x Pre-release forums (retired) / Find Generic Content on the page

Find Generic Content on the page

9 posts, 0 answered
  1. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    10 May 2007
    Link to this post
    Hello

    Based on following code I am collecting Generic Content that is defined on the page that I search via SiteMap.Provider.FindSiteMapNode(_pageUrl).
    The generic content is found, but the problem is that the content is always the content of the first version of the page.

    How is it possible to get the last version of the page and collect the correct Generic Content?

    Regards
    Luc

    startNode = SiteMap.Provider.FindSiteMapNode(_pageUrl)
    If Not startNode Is Nothing Then
        
    startPage = startNode.CmsPage

        'walk through page controls
        
    If startPage.Controls.Count > 0 Then
            
    Dim textSplit As String()
            
    For Each cmsControl In startPage.Controls
            
    Try
                
    If Not cmsControl.ControlType Is Nothing Then
                    
    If cmsControl.ControlType.Name = "GenericContent" And cmsControl.ContainerID = "RightContent" Then
                        
    If cmsControl.Properties.Count > 0 Then
                            
    For Each cmsProperty In cmsControl.Properties
                                
    If cmsProperty.Name = "Content" Then
                                    
    Dim s As String
                                    
    textSplit = cmsProperty.Value.Split(New [Char]() {_seperator})
                                    
    For Each s In textSplit
                                        
    If s.Trim() <> "" Then
                                            
    al.Add(s)
                                        
    End If
                                    
    Next s
                                    
    Exit For
                                
    End If
                            
    Next
                        
    End If
                    
    End If
                
    End If
                
    Catch ex As Exception
            
    End Try
        Next
        
    End If
    End If

  2. Bob
    Bob avatar
    330 posts
    Registered:
    24 Sep 2012
    10 May 2007
    Link to this post
    Hello Luc,

    The CmsPage property of the node returns the last published (public) version of the page. To get the last edited version you can use Staged property of CmsPage.

    startPage = startNode.CmsPage.Staged

    startPage should be declared as IPageBase.

    Sincerely yours,
    Bob
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    10 May 2007
    Link to this post
    Hello Bob

    But I need the last published version of the page.

    I changed the code accordingly the suggestions of you. At that moment I got the last version of the page. But after I made some changes to the page again, those changes were not presented.
    I changed the code back to the original and at that moment I got the last version of the page. I made some changes again, and again those changes were not presented.

    Has it something to do with caching that the last version is not presented?

    Regards
    Luc
  4. Bob
    Bob avatar
    330 posts
    Registered:
    24 Sep 2012
    10 May 2007
    Link to this post
    Hello Luc,

    Well in this situation your code should work fine but I guess there is a bug in RC2. Please try the following code as workaround:

    Dim startNode As CmsSiteMapNode = SiteMap.Provider.FindSiteMapNode(_pageUrl)  
    Dim manager As New CmsManager()  
    Dim page As IPage = manager.GetPage(startNode.CmsPage.ID)  
     

    If you want to get the current page there is more efficient way to do it:
    CmsUrlContext.Current.PageID

    All the best,
    Bob
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    10 May 2007
    Link to this post
    Hello Bob

    Thanks. This workaround works for me fine.

    Regards
    Luc
  6. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    14 May 2007
    Link to this post
    Hello Bob

    The code I used for getting the content on a page doesn't work in all situation and I don't know why it sometimes works and sometimes not.

    I use the code as described before extended with the workaround

    Dim startNode As CmsSiteMapNode = SiteMap.Provider.FindSiteMapNode(_pageUrl)  
    Dim manager As New CmsManager()  
    Dim page As IPage = manager.GetPage(startNode.CmsPage.ID) 


    But the cmsProperty.Value only contains something like 628417f7-2f80-4cfb-b8db-02263bfceed4.....

    Should I use another way to get the defined generic content of a page?

    Regards
    Luc
  7. Bob
    Bob avatar
    330 posts
    Registered:
    24 Sep 2012
    15 May 2007
    Link to this post
    Hi Luc,

    That means the control is using shared content. You can retrieve the shared content like this:
    ContentManager cntMngr = new ContentManager("Generic_Content");  
    IContent cntItem = cntMngr.GetContent(new Guid("0455063F-B170-460b-BD55-3567259B5C4A"));  
    string text = cntItem.Content as string

    Note if you are using multiple content providers you need to retrieve the name of the provider as well:
    cmsProperty.Name == "ProviderName";

    Regards,
    Bob
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Luc Baeten
    Luc Baeten avatar
    169 posts
    Registered:
    23 Sep 2005
    16 May 2007
    Link to this post
    Hello Bob

    The thing is that the control doesn't use shared content.
    In the official version that is released yesterday (congratulations!), is there an example how to get the content of a page?

    Regards
    Luc
  9. Bob
    Bob avatar
    330 posts
    Registered:
    24 Sep 2012
    17 May 2007
    Link to this post
    Hello Luc,

    Unfortunately we do not have examples for this yet. Improving our documentation is our heist priority right now. We will release a service pack with full documentation and more examples in Jun.

    The way you do it is fine and the behavior you describe is rather strange. Feel free to send us your project and we will investigate.

    Best wishes,
    Bob
    the Telerik team

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