Page name source from multiple fields

Peter Otmar asked on August 12, 2016 09:04

Hi, Is it possible to create page name from multiple source fields with optional formatting?

For example I have start time and end time fields and want to have the page name as 9am-10am

Thanks

Correct Answer

Dawid Jachnik answered on August 12, 2016 09:20

Hello Peter,

Is it possible. I have almost the same on one of the pages. You need to use Global Events, here's my snippet of my code:

using CMS.Base;
using CMS.DocumentEngine;
using CMS.Helpers;
using System;
using System.Globalization;


/// <summary>
/// Summary description for RedakcjeHandler
/// </summary>
[RedakcjeHandler]
public partial class CMSModuleLoader
{

private class RedakcjeHandler : CMSLoaderAttribute
{
    public override void Init()
    {
        DocumentEvents.Insert.Before += Document_Insert_Before;
    }

    void Document_Insert_Before(object sender, DocumentEventArgs e)
    {
        TreeNode doc = e.Node;

        if (doc.ClassName.ToLower() == "ministranci.czytanie")
        {
            CultureInfo k = new CultureInfo("pl-PL");
            DateTime dt = doc.GetDateTimeValue("Data", DateTimeHelper.ZERO_TIME);
            dt = CMS.Globalization.TimeZoneHelper.ConvertToSiteDateTime(dt, CMS.SiteProvider.SiteContext.CurrentSite);
            string tytul = dt.ToString("dd MMMM", k).TrimStart('0');
            tytul += " - " + doc.GetValue<string>("Rok", "Rok A");
            e.Node.SetValue("Tytul", tytul);
            e.Node.DocumentName = tytul;
            e.Node.NodeAlias = tytul;
        }


    }
}
}
3 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Otmar answered on August 13, 2016 08:35

Thanks Dawid, great solution.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.