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

Page variables in Meta tag

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. bnye
    bnye avatar
    332 posts
    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.


  2. Vlad
    Vlad avatar
    498 posts
    19 Jun 2017
    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");

    Hope this will help.

    All the best,
    the telerik team

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