4

I am trying to do some validation on saving a page. Part of this involves checking the page template. When I try to read it, however, I get the default value for the page template. This is even after changing it.

In this example item.PageTemplate.Title shows "Default Page Template" even though I have selected "Specific Page Template".

namespace Tridion.EventSystem.Extensions.OnSaveValidation
{
    [TcmExtension("Check Items On Save")]
    public class CheckItemsOnSave : TcmExtension
    {

        public CheckItemsOnSave()
        {
            EventSystem.Subscribe<Page, SaveEventArgs>(HandlerForSavePage, EventPhases.Initiated);
        }

        public void HandlerForSavePage(Page item, SaveEventArgs args, EventPhases phase)
        {
            if (item.PageTemplate.Title != "Specific Page Template")
            {
                throw new Exception("Incorrect Page Template: " + item.PageTemplate.Title);
            }
        }
    }
}
5

You're using the Initiated event phase, so the data for the page hasn't been changed by Tridion yet. Change your subscription to hook into the EventPhases.Processed phase and you should see the updated information but still have the opportunity to throw an exception and reject the change.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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