More in this section

Forums / Developing with Sitefinity / Create Title programmatically from another metafields

Create Title programmatically from another metafields

5 posts, 0 answered
  1. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    06 Apr 2008
    Link to this post
    Hi,

    It's possible to create the title of one article of Generic contents module (news)from another metafields. Like Title is Ref + Author. How to declare in this case in web.config and templates. We need to extend as custom modules and how to
    Thanks very much for help.

    Regards 
  2. Vassil Daskalov
    Vassil Daskalov avatar
    261 posts
    Registered:
    18 May 2013
    07 Apr 2008
    Link to this post
    Hello Pierre,

    Yes, this could be easily done through the Executing event handler. All you need to do is subscribe from the global.asax Application_Start event to the ContentManager.Executing event and on the event handler do the logic you need. Sample pseudo code would look like this:

    void Application_Start(object sender, EventArgs e)   
    {  
        Telerik.Cms.Engine.ContentManager.Executing += new EventHandler<Telerik.ExecutingEventArgs>(ContentManager_Executing);  
    }  
     
    void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e)  
    {  
        if (e.CommandName != "DeleteContent")  
        {  
            Telerik.Cms.Engine.IContent cnt = e.CommandArguments as Telerik.Cms.Engine.IContent;  
            if (cnt != null)  
            {  
                cnt.SetMetaData("Title", (string)cnt.GetMetaData("Author") + " - " + (string)cnt.GetMetaData("Title"));  
            }  
        }  

    Hope this would do the job.

    All the best,
    Vassil Daskalov
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    07 Apr 2008
    Link to this post
    Hi Vassil,

    Many Thanks. After add this expression in my Global.asax, Could you explain more how to use with the News Module. What I need to make? Delete the input title ID or some else. How to limit only for this News Module or extent to events module but with another metafields like where+when+date.

    regards
  4. Nikifor
    Nikifor avatar
    232 posts
    Registered:
    18 May 2013
    11 Apr 2008
    Link to this post
    Hi Pierre,

    In order to have this information applied to the news items, you should make verification first for checking if the current content item uses the News provider. Here is an example code:

        void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e)  
        {  
            if (e.CommandName != "DeleteContent")  
            {  
                Telerik.Cms.Engine.IContent cnt = e.CommandArguments as Telerik.Cms.Engine.IContent;  
                if (cnt != null && cnt.ProviderName == "News")  
                {  
                    cnt.SetMetaData("Title", (string)cnt.GetMetaData("Author") + " - " + ((DateTime)cnt.GetMetaData("Publication_Date")).ToString());  
                }  
            }  
        }  
     

    If you want to use different Meta Fields, you should use the method GetMetaData of the IContent object. You can use the same example by inputting the Meta Field, from which you want to get the information. Once you get this information, you can cast it to the correct type. For example: Publication_Date field to DateTime.

    Kind regards,
    Nikifor
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    11 Apr 2008
    Link to this post

    Hi Nikifor,

    Many thanks. Today I've one error with Image&Doc Title name, This is a good fix for this. Now when can add the title programmatically from others Metafields. Great tip!

    Regards

     

Register for webinar
5 posts, 0 answered