10

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:

  1. The page was created in a structure group with a default page template assigned to it AND
  2. 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?

1 Answer 1

4

This behaviour does makes some sense because in the Initiated phase you haven't actually saved or applied a page template, so the CM doesn't know about it yet.

The reason that the Default Page Template info is available is because it's already pre-configured on the SG (or that SG's parent SG or the Publication) so the Content Manager knows about it before you actually save the page. Here is a screenshot of SG's properties for your reference:

enter image description here

Instead of the Default PT, try to pre-set your PT on the Structure Group's properties. Hopefully you'll get the PT's title then.

You could also try changing your event to fire in the Processed phase. This way the CM would have processed the page save event applying the selected PT, but not yet saving/committing it. So you may be able to swap the file name at that stage just in time for the commit (I'm not 100% if this will work).

3
  • Thanks for your reply Nickoli.. For the SGs which are pre-set with my intended PT, it is working fine, but our problem is with the structure groups which were already pre-set with other PTs. And also this problem is for the first most save only. Later onwards its getting correct PT which we selected, since its already saved. And coming to Processed phase, it is almost equal to Committed phase, where we are unable to modify the page name. It means the page name is not modified in these phases. Jul 5, 2013 at 5:18
  • Thanks for your quick answer Nickoli, as Koti indicated in his comment we had tried using the processed phase but found it to be too late in the cycle. Given your suggestion however, I am going to go back and review exactly what we tried in the processed phase just to make sure we didn't overlook something. It does seem a little strange to me that in the initiated phase we would have access to everything else about the page (filename, component presentations etc.) but not the template name. Jul 6, 2013 at 21:57
  • As you mention, it is strange indeed. It could be a defect. Have you applied HR2? If so and still seeing the issue, filing a ticket with support may not be a bad idea. Jul 7, 2013 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.