Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

[CONFLUENCE] How can I use VTL to find the home page of a space? (content.getAncestors)

Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2012

Hi all,

I'm trying to find out what the home page of a space is. I'm aware of '$content.getAncestors().get(0)', which can be used to get the full name (i.e., not the display title) of a page. However, when I try to use this in a user macro on the home page itself, it throws up an exception ("Error occurred rendering template content").

Is there another way to find out what it is?

Also, is there a way of getting the display name of the home page too?

I can't seem to find anything in the API documentation relating to '.getAncestors', and doing something trippy like $content.getAncestors().get(0).getDisplayTitle() doesn't work. Can someone point me in the right direction?

2 answers

1 accepted

1 vote
Answer accepted
Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2012

I've found one solution I'm after.

You can use

$content.isRootLevel()

To find out if it is the home page in a space. This provides a simple boolean answer.

0 votes
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2012

There's the $content.isHomePage() method. I'm not sure I get exactly what you're doing, but you might be able to iterate over all the pages until you find the home page. Something like this (not tested):

#if ($content.getAncestors())
  #set($ancestors = $content.getAncestors())
  ## iterate over the ancestors
  #foreach ($p in $ancestors)
    ## do your checking here by getting the content object and then calling isHomePage()...
  #end
#end

Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2012

I'm trying to write a conditional in a macro that will run part of the macro of if it is/isn't the home page.

I added the following to the loop but I still get a template error on the home page:

#if ($p.isHomePage())

<p>$p is the home page</p>

#end

Steve Goldberg
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2012

Question: why does $content.getParent().getDisplayTitle work but not $content.getAncestors().get(0).getDisplayTitle? I'd also like to get a list of child page names, e.g., $content.getSortedChildre().getDisplayTitle, but this doesn't work either.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events