2

we need to validate the Component Template selection on Page Saving. if we did not select the CT, now we are able to save the Page but on publish time it's throwing an error.

can anyone help me how to write the logic for mandatory CT selection with JS or Event system? please share any code samples for PagePresave.

we are using SDL Tridion 9.6. we need compatible for New UI and Classic UI as well.

3 Answers 3

2

There's an example of that in this blogpost: http://nunolinhares.blogspot.com/2012/07/validating-content-on-save-part-1-of.html

The code in there is for a Component save, but should be very simple to change it to a page.

I guess this is the key part:

EventSystem.Subscribe<Component, SaveEventArgs>(ValidateFirstLetterIsUpperCase, EventPhases.Initiated);

Change Component to Page, and you now have an event triggered when a page save is Initiated (PagePreSave as you call it).

1

I'm not sure if this applies to you, but if you don't want to use templateless publishing at all, you can switch it off by setting an environment variable. See https://gateway.sdl.com/apex/communityknowledge?articleName=000015847. If you do that, users will have to select a component template once again.

1

The fact that use of Component Templates is no longer enforced is a side-effect of the introduction of the data pipeline in Tridion Sites 9.5. This data pipeline does not require templates and therefore it is possible to put Components on a page without a Component Template.

As Quirijn mentioned, if you really don't need this data pipeline at all, you could disable it altogether. Note, however, that you also need the data pipeline if you want to use the integrated CD search capability.

As Nuno mentioned, you can easily write an event handler that prevents users from saving a Page with "templateless" Component Presentations, but usability-wise that may be worse than a system which ensures that a Component Template is always (implicitly) selected.

As a third option, you could look into using Page/Region Schemas to define Component Presentation constraints and thus force the use of (certain) Component Templates.

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.