We're using an event to manipulate the file name of a page before it is saved on a Tridion 2011, SP1 HR1 installation.
We've actually been doing this for years ever since we first implemented Tridion. Until now we've been performing the same manipulations of the file name regardless of the type of page but we now have a requirement to perform an additional change to the file name for one specific type of page.
The issue we are running into is we are having problems getting the Title of the page template in some circumstances to implement these rules:
We are subscribing to the Initiated phase of the Page Save event:
namespace EventSystem
{
[TcmExtension("Tridion2011EventSystem")]
public class Events : TcmExtension
{
public Events()
{
Subscribe();
}
public void Subscribe()
{
EventSystem.Subscribe<Page, SaveEventArgs>(OnPageSavePre, EventPhases.Initiated);
}
private static void OnPageSavePre(Page page, SaveEventArgs args, EventPhases phase)
{
FileFolderNamesHandler.FileNamesHandle(page);
}
}
}
This eventually results in a call to the method FileFolderNamesHandler.FileNamesHandle(page)
where we modify the filename associated with the page:
namespace EventSystem.EventHandlers
{
public class FileFolderNamesHandler
{
private const string SchemaOrTemplateNameString = "article";
public static void FileNamesHandle(Page page)
{
var tmpFileName = page.FileName.ToLower();
if (page.PageTemplate.Title.Equals(SchemaOrTemplateNameString,
StringComparison.InvariantCultureIgnoreCase))
{
// Do some stuff related to manipulating the file name
// specific to the article page template
}
page.FileName = tmpFileName;
}
}
}
In FileNamesHandle()
we are trying to check the title of the page template of the page being saved. This works fine when:
- The page was created in a structure group with a default page template assigned to it AND
- The default page template was not overridden
However, if we create the page in a structure group without a default page template or if we override the default page template, the PageTemplate.Title for the selected page template doesn't seem to be available to us until after the page has actually been saved.
Any thoughts as to what might be going on here and how we may be able to retrive the selected page template name in all cases?
Why would the page template title be available for the page if it is the default page template for items created in the structure group and not available if it isn't?