Skip to end of metadata
Go to start of metadata

Hi,
I have been using create-child for a while now and I am currently trying to expand my use to automatically create a 4 deep directory structure of pages.

I have been half succesful in that I can create the directory structure that I want but not without issues. The directory structure I want is:

Parent Page

  • Child Level 1
  • GrandChild Level 2
  • GreatGrandChild Level 3

The problem I have is child pages show up as children for their parent and all other higher order Grand Parents. I am thinking this might be a bug in the Create Child macro or it may just be how Confluence deals with this. Either way, I am hoping there is a workaround or patch which can be applied.

To try and explain the exact issue .....

What happens is when creating the child, grandchild and greatgrandchild pages, these pages are also created in the parent page which calls the create-child macro.

At the moment, how I create the directory structure is I create the Parent Page from Template A.
Template A calls the create-child page to create Child Level 1 page which references Template B.
Template B calls the create-child page to create GrandChild Level 2 page which references Template C.
Template C calls the create-child page to create GreatGrandChild Level 3 page.

This results in the following........

The Parent Page has the following Children:
Child Level 1
GrandChild Level 2
GreatGrandChild Level 3

Child Level 1 page has the following chidlren:
GrandChild Level 2
GreatGrandChild Level 3

GrandChild Level 2 page has the following chidlren:
GreatGrandChild Level 3

GreatGrandChild Level 3 page does not have any child pages.

In effect what has happened is the Parent Page has executed the create-child macros which result from calling Template B.

Similarly, Child Level 1 has executed the create-child macros which result from calling Template C.

Hopefully this paints a clear picture of what is going on.

Has anyone else seen this issue or been able to reproduce it? Any help in overcoming this issue would be greatly appreciated.

Mick

  • No labels

15 Comments

  1. If i understand you correctly then you can do this using space/global templates, eg:

    Create a template called 'grandchild' which contains:

    {create-child:GreatGrandChild Level3|template=greatgrandchild|render=true}
    

    Create a template called 'child' which contains:

    {create-child:GrandChild Level2|template=grandchild|render=true}
    

    Then for your root level you will use:

    {create-child:Child Level1|template=child|render=true}
    

    What happens is that at the root level, the first create-child is executed, it loads the child's content from the 'child' template, this template is then rendered (without being displayed), this causes the create-child in the child-template to be executed, which in turn generates the GrandChild page ... rinse & repeat.

    This should result in the following structure:

    • Parent's sibling
    • Parent's sibling
    • Parent
      • Child
        • GrandChild
          • GreatGrandChild
    • Parent's sibling
    • Parent's sibling
    • Parent's sibling
    1. Unknown User (mroff@hemispheregps.com)

      Thanks for the prompt reply.
      I will give this another go tomorrow, but i am pretty sure i had pretty much this and encountered the problem described.
      Does this work for you even if you just try one levl down to grandchild?
      Mick

  2. Unknown User (ville.valtasaari@thl.fi)

    Hi,

    I tried using this in the default space content so that creating a space would create two orphan pages using pages from an existing space as templates. Those two pages were to create further children for themselves, again using pages from an existing space as templates.

    The first two pages were created, but under the new space home page, not as orphans. The new pages had no content, so the template functionality didn't seem to work. Since the template pages with their additional create-child-macros were not used, no further pages were created.

    Confluence 3.0.2.

    Ville

    1. {create-child:my page|parent=@orphan|template=mytemplate|render=true}
      

      You can find complete documentation for the macro in the confluence notation guide.

      NB: if you do not include the render=true then the child pages will not be created until you view the pages.

      1. Unknown User (ville.valtasaari@thl.fi)

        Thanks,

        But apart from using the space:pagename pattern for the template, those parametres were what I used. As the parent=@orphan and the template=space:pagename parametres failed, I don't know if the render bit worked.

        Could it have something to do with my trying to use them at space creation by puttin the macro in the space default content?

        Regards,
        Ville

        1. Yes, that's entirely possible ... create-child has not been tested in that context

          One solution would be to remove the render=true from your base-layer (the space content), then view the space homepage to create the pages.

          1. Unknown User (ville.valtasaari@thl.fi)

            Well,

            Whatever I do, I can't seem to get parent=@orphan or parent=@space to work. If a page is created, it will be created as a child of the page with the macro. Using a page in another space as a template doesn't work either (template=spacekey:Page Name).

            Regards,
            Ville

            1. I've created an issue in our internal tracker to check on this ... if you need a resolution within any defined timescale then you will need to take out a support contract

              1. Unknown User (ville.valtasaari@thl.fi)

                Thanks,

                Let me know if you need any more info.

                r. Ville

  3. Unknown User (mroff@hemispheregps.com)

    I went through and created fresh local templates for parent, child, grandchild and greatgrandchild.
    Initially I got very strange results where the child page was referencing an existing page. I don't know and sort of don't care why this was happening - I renamed the offending page that was there to something else and retested.

    This time it all worked as it should. My implementation of this was a little different as I appended the title of the parent page to the end of child, grandchild and greatgrandchild but I haven't been able to test if I can get this to work yet as my Confluence implementations (both LIVE and TEST )are playing up with the create-child macro. The teamples and throwing Null-Pointers and my pages are dying if I use create-child in them.

    As soon as I have this issue sorted I will see if I can create my directory structure with the appended parent name in the title of all descendent pages.

    Thanks for the help Alain - I'll let you know how this works out and if I get it working I will post up the code so others might be able to use it in the future.

  4. Unknown User (mroff@hemispheregps.com)

    OK so it seems I was doing some very nasty things in my template to the Confluence database which is why I was seeing errors.

    The crux of my template went something like this....

    parent Template

    {report-on:injected=true}
    {create-child:CHILD - %content:title%|template=child|render=true}
    {report-on}
    

    child Template

    {report-on:injected=true}
    {create-child:GRANDCHILD - %content:parent > content:title%|template=grandchild|render=true}
    {report-on}
    

    grandchild Template

    {report-on:injected=true}
    {create-child:GREATGRANDCHILD - %content:parent > content:parent > content:title%|template=greatgrandchild|render=true}
    {report-on}
    

    The report must have been doing something because it created a page without a title which then corrupted the database.

    This sort of puts an end to my directory strucutre as I need to create multiple project directories in the one space. I was going to differentiate each of the pages through the use of the project title page.

    I may end up looking at a copy page (and all children) option which gives you the option to copy a heap of pages and modify their names based on certain inputs. I haven't used this before but I think it looks like the next option.

    Thanks Alain for your help with this one.

    1. I've created an issue in our internal tracker to alter create-child so that it throws an error if you try to create a page with a blank title.

      1. Unknown User (mroff@hemispheregps.com)

        Yeah I think that would be helpful.

  5. Unknown User (mroff@hemispheregps.com)

    One more question .....
    I have got my directory structure working now with Create Child.
    I have created my templates as Global Templates but I have found that child templates do not render until the page is opened. All the pages in the first template render ok, but no pages underneath the parent template render until you open the page.

    This is my code to the parent template.

    {report-block}
    {local-reporter:page:creation date}
    {date-filter:creation date|beforeValue=-60s|format=hh:mm:ss dd MMM, yyyy}
    {local-reporter}
    {report-body}
    {replace-and-render} {replace-body} 
    {create-child:Child 1 - %title%|parent=@self|template=child 1 template|render=true} 
    {create-child:Child 2 - %title%|parent=@self|template=child 2 template|render=true} 
    {replace-body} {replace-item:%title%} {report-info:report:root content > page:title} {replace-item} {replace-and-render}
    {report-body}
    {report-block}
    

    This is my code to the child 1 template.

    This is the Child 1 page
    
    {report-block}
    {local-reporter:page:creation date}
    {date-filter:creation date|beforeValue=-60s|format=hh:mm:ss dd MMM, yyyy}
    {local-reporter}
    {report-body}
    {replace-and-render} {replace-body} 
    {create-child:Grandchild 1 - %title%|parent=@self|render=true} 
    {replace-body}
    {replace-item:%title%} {report-info:report:root content > page:parent > page:title} {replace-item} {replace-and-render}
    {report-body}
    {report-block}
    

    In the example above, the parent page successfully has Child 1 and Child 2 created, but the Grandchild 1 page is not created under neath Child 1 until Child 1 is accessed.

    This issue does not occur when the templates are setup as Space Templates.

    Is this how it is suppose to work or is this a bug with global templates?

    1. Unknown User (mroff@hemispheregps.com)

      CORRECTION

      This issue occurs in both the Global and Space templates. I didn't notice it before in my local space testing.

      I believe this issue is resulting from an incompatibility of the create-child macro running within a report.

      The purpose of the report is to give access to grandparent and greatgrandparent titles.

      Is there a way to use the

      {page-info:page:title}
      

      macro but to give the title of a grandparent or greatgrandparent?