Get page name where web part is located with macro

Jake Burgy asked on August 18, 2015 17:11

If I have the following document structure

  • Site Area A (Menu Template)
    • Subpage 1 (Page Template, nested content)
    • Subpage 2 (Page Template, nested content)
    • Subpage 3 (Page Template, nested content)
  • Site Area B (Menu Template)
    • Subpage 1 (Page Template, nested content)
    • Subpage 2 (Page Template, nested content)
    • Subpage 3 (Page Template, nested content)

Where the "Menu Template" has a left nav, and the subpages just have editable text areas to the right of the menu, in the main content area (using page nesting).

I want the templates to be shared (because the left nav menu is auto-generated using a Hierarchical Viewer which is good), but what I want to be able to do is display the name of the page where the "Menu" web part is on the Menu Template, even on sub-pages.

For example, in my menu, if I set the menu header to {% CurrentDocument.DocumentName %}, it displays "Site Area A" on the menu on the Site Area A page, but if I navigate to "Subpage 1", it says "Subpage 1", but I still want it to display "Site Area A". So, I want the name of the document where the web part actually resides, not necessarily the current page, in a nested page structure.

How would I go about doing this with a macro?

Correct Answer

David te Kloese answered on August 18, 2015 18:38

Hi,

You could also try this macro:

{%Documents["/" + CurrentDocument.NodeAliasPath.Split("/")[1]].DocumentName%}

Depending on your level you can replace the [1] of course!

details from older post: http://devnet.kentico.com/forums/f65/t43646/root-document-name-macro

David

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on August 18, 2015 18:31

As long as your editable text webpart is on your parent page template and you have the subpage placeholder on that parent page template, this should work. I set the webpart to have default text of {% CurrentDocument.DocumentName %} in the properties, not in the actual Page content. I don't have "inherit content if empty" checked. And it shows on sub pages. I have a structure of:

/About
/About/History
/About/Organization

And on the History and Organization pages, it displays "About" above the navigation. Very similar structure/format as you have.

0 votesVote for this answer Mark as a Correct answer

Jake Burgy answered on August 18, 2015 18:42

@Brenden, The macro is in the HTML Envelope, so I'm sure if I shifted a few things around or placed the header in a separate web part, that would probably work. Because it's in the envelope, though, I think that's why it isn't working.

@David, that worked for me. Thanks!

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on August 18, 2015 20:24

David's solution works although it executes another query on the the full content tree which is unnecessary processing for a very simple task. I'd be careful with that macro.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.