2

In code, how can I access the current Page Design my Page is using?

Tried to find something in the RenderingReference no luck.

3

That is quite simple, you need to use PresentationContext service. Here is an example:

ServiceLocator.ServiceProvider.GetService<IPresentationContext>().GetDesignItem(CONTEXT_ITEM);

It will do all the work your you:

  1. check if there is design selected on your page
  2. check design rules
  3. and at the end check Template to Design Mapping field (if design won't be resolved from above ones)

You can also inject PresentationContext using constructor injection like this:

public class MyClass
{
    protected readonly IPresentationContext PresentationContext;

    public MyClass(IPresentationContext presentationContext)
    {
        PresentationContext = presentationContext;
    }
}
  • Works like a charm thank you. Is this somewhere documented? These GetService() is new for me, I have seen in the showconfig.aspx that there are a lot more of these ServiceTypes, just wondering what each of them is able to provide. – Bgl86 Aug 24 at 12:11

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.