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

Forums / 3.x Pre-release forums (retired) / Page variables in Meta tag

Page variables in Meta tag

2 posts, 0 answered
  1. bnye
    bnye avatar
    332 posts
    Registered:
    22 Sep 2005
    02 Apr 2007
    Link to this post
    I have a need to store a custom property for each page. In order to do this I have added a Meta tag for the variable. How can I get access to this variable from the cmspage object. I can see that the meta tags are stored in the sf_HtmlAttributes table. If anyone has a better idea of where to put this variable that would be fantastic.

    Sincerely,

    Ben
  2. Vlad
    Vlad avatar
    498 posts
    Registered:
    15 Jul 2016
    03 Apr 2007
    Link to this post
    Hello Ben,

    You can access the page Meta tags by iterating through the HeaderControls collection of the cmspage object.
    For each HeaderControl object in the collection you can invoke LoadControl() method to get the System.Web.
    UI.Control object. For the Header controls, the returned type could be System.Web.UI.HtmlControls.HtmlMeta, System.Web.UI.HtmlControls.HtmlLink or System.Web.UI.HtmlControls.HtmlGenericControl. Then you can access the Attributes collection of the returned from LoadControl() HtmlControl object.
    Another approach is to access directly Attributes collection of the HeaderControl.
    If you intend to change HtmlControl data, i.e. properties, attributes, etc. you have to join the HeaderControl object into a transaction first, and finally when you want to apply changes, you have to Commit the transaction.

    But the above solution will be obsolete in the upcoming release of Sitefinity, because the API of the CMS module has been changed regarding Partially Trusted support implementation and some improvements.
    So, here is an approach which you should use in the Sitefinity RC2, for example adding a head tag to a page:

     CmsManager manager = new CmsManager();
     bool forEdit = true;
     IPage page = manager.GetPage(pageId, forEdit);
     HtmlMeta meta = new HtmlMeta();
     meta.Attributes.Add("name", "description");
     meta.Attributes.Add("content", "test");
     page.AddHeaderControl(meta);
     manager.SavePage(page);

    Hope this will help.

    All the best,
    Vlad
    the telerik team

    Instantly find answers to your questions at the new telerik Support Center
2 posts, 0 answered