How do I determine the current pages document type in umbraco?

shawty picture shawty · May 26, 2013 · Viewed 28.7k times · Source

I have what I feel is a very simple question about Umbraco, but one that has as of yet no apparent answer.

I have a razor template, standard stuff, with @ displaying variables and some inline C# code.

At one point in the template I use:

@Umbraco.RenderMacro("myCustomMacro");

no problems there, everything works as expected.

Now, this macro is inserted on every page (it's in the master template) but I have a page property that allows the content authors to turn it on and off via a check box in the page properties, again so far so good everything works perfectly.

However I now find that for a certain "document type" this component MUST be displayed, so I've been trying to find a way to perform that check.

Now in my mind, this should be as simple as doing something like this:

@{
  if(CurrentPage.documentType == "someDocTypeAliasHere")
  {
     //Render the macro
  }
  else
  {
     // Render the macro only if the tick box is checked
  }
 }

as I say, this is (or I believe it should be anyway) a very simple operation, but one that so far does not seem to have a result.

What Have I tried so far?

Well apart from reading every page on our-umbraco that mentions anything to do with razor & the @CurrentPage variable, Iv'e been through the razor properties cheat sheet, and tried what would appear to be the most common properties including (In no specific order):

@CurrentPage.NodeTypeAlias
@CurrentPage.NodeType
@CurrentPage.ContentType
@CurrentPage.DocumentType

and various letter case combinations of those, plus some others that looked like they might fit the bill.

Consistently the properties either don't exist or are empty so have no useable information in them to help determine the result.

So now after a couple of days of going round in circles, and not getting anywhere I find myself here..

(Please note: this is not a search the XSLT question, or iterate a child collection or anything like that, so any requests to post XSLT, Macros, Page templates or anything like that will be refused, all I need to do is find a way to determine the Document Type of the current page being rendered.)

Cheers

Shawty

PS: Forgot to mention, I'm using

umbraco v 4.11.8 (Assembly version: 1.0.4869.17899)

Just in case anyone asks.

Answer

user3887964 picture user3887964 · Jul 29, 2014

In Umbraco 7 use currentPageNode.DocumentTypeAlias