9

Is there a way to access page metadata schema value or structure group metadata value holding that page from the C# Code fragment which is used in the component template?

7

It is generally considered bad practice to access Page level information from Component templates (Separation of concerns etc.). It is something which was easy in the old days of VBScript templating and sometimes caused a lot of issues.

There are ways to do it though, if you must. Take a look at Access container page of a component in .net based CT on Stack Overflow

| improve this answer | |
  • Oh I love that: "Generally considered bad practice"... "sometimes caused a lot of issues". Sure - I'd prefer to see the PT pass the relevant data to CT scope, but if you're going to be so dogmatic, you owe us a blog on the subject! :-) – Dominic Cronin Apr 4 '13 at 15:05
  • 2
    I will add it to the list of (nonexistent) blog posts to write. Be advised, it's a LONG list ;) – David Forster Apr 4 '13 at 21:06
7

Have a look at the code sample for the third option suggested in the answer here: https://stackoverflow.com/questions/11182669/how-do-i-pass-arguments-down-to-component-dreamweaver-templates

I believe it's exactly what you're looking for, however, as David suggests in his answer, it's better to avoid reaching to page-level scope from your CT.

| improve this answer | |
2

Thanks to David Forster/Jeremy Grand Scrutton for providing option to access the page object from the component template which really works in my scenario & the same solution is provided by one of my colleague.

Page page = engine.PublishingContext.RenderContext.ContextItem as Page;

if (page != null) { }

The only limitation with this option is that it is not available during previewing of the page or debug the PT/CT using template builder.

| 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.