2

In Order to make my logo dynamic(coming from CMS), I created a CT which can add any image to a header page having PT "Include Page".

But Now I want that CT to be available for one page i.e. header page only. As that CT can be added to any page and it is rendering a logo of that specific page which shouldn't be the case.

Any suggestions?

  • This issue seems like a yet to be implemented feature..a number of schema can be used for a CT..same should be with option to include CTs available for a PT.. – Bhawna Jain Mar 12 '18 at 12:16
  • 1
    The ability to limit the allowed CTs for a given page is actually in the product but only in Experience Manager (XPM), through XPM regions. Your thinking also aligns with the XPM Page Type and Content Type concepts, which offer preselected Component + CT options or predefined (prototyped) Component Presentations, respectively. There's also an option to restrict the allowed Content Types for a given Page Template, but only in XPM for now. – Alvin Reyes Mar 12 '18 at 18:52
4

Another option would be to use Event System on Page Save and interrupt the saving if the Page Template <-> Component Template combination is not allowed. You can throw an exception with a meaningful message informing the Editors that what they're trying to achieve is not permitted.

The advantage of this approach is that you handle your specific case even before it's created VS throwing and exception from Templating or not rendering it at all (effectively masking the Component Presentation). In other words, you have a clean slate as far as the PT/CT combinations goes, effectively having a clearer overview of the current state of the system.

Naturally, this also has drawbacks, for example it will get executed each time a Page is saved slowing the system a bit, but the main concern is what about the already existing Pages which have the forbidden Component Template. For those, you could use Core Service to do a quick search and remove the Component Presentation from them.

2

There is no "out-of-the-box" to do this restriction - it may be coming with Region support in Tridion Sites 9, as I understand you can add restrictions like this to a region.

For now, the only way to do this is to enforce it in your Page Template - i.e., either throw an exception when you find this CT in a PT that shouldn't be used, or not render it at all - though this is not ideal, as you would have to change all Page Templates.

Edit - You could also put this logic in the CT itself, using the engine's render context (see here for more info) property to find if you're rendering in the correct page type.

  • So,Engine.PublishingContext.RenderContext.ContextItem will return PT,but I am getting error "Engine doesn't exist " :| – Bhawna Jain Mar 12 '18 at 12:05
  • Probably missing some namespace declaration? I have no trouble finding it under engine. What version of Tridion are you using? – Nuno Linhares Mar 12 '18 at 12:18
  • I think its SDL v8.1.0 – Bhawna Jain Mar 13 '18 at 4:05
  • That should be fine, this property exists at least since T2013, probably earlier. – Nuno Linhares Mar 13 '18 at 6:59
1

A possible workaround would be to put the new Component Template into a different folder than your other 'editorial' Component Templates and then control the security permissions on that folder.

This would mean that only Tridion Administrators (and other Users/Groups that you choose) will be able to see the new Component Template as an option when adding Component Presentations to a Page.

1

You could do something like this in your page template.

engine.PublishingContext.RenderContext.ContextVariables.Add(
                                                "allowDynamicLogo", true);

In your component template, you could read the context variables to see if this one is present, and if it's not, throw an exception.

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.