Block creation of pages without template
Asked by Luana Premoli:

Hi guys...  

We need to block people from creating new blank pages.

We have templates created for all types of articles, which already apply the correct label and a custom header, however, people end up creating a blank page and are not using the predefined templates.

Is it possible to allow the creation of pages only via template and block the creation of blank pages?

Version: Confluence 7.13.9


Answers:
author: Nicolai Sibler
body: Hi [@Luana Premoli](/t5/user/viewprofilepage/user-id/5184366) ,

you can hide the *Create* button by placing the following to   
Confluence Administration ? Custom HTML ? At the End of HEAD:

```
<script type="text/javascript">
AJS.toInit(function(){
    AJS.$('#quick-create-page-button').hide();
});
</script>
```

Please note:

* That's a site-wide functionality and can be done by Confluence Admins only
* Creating blank pages will still work using the shortcut **c**

Hope that helps!

Kind regards,

Nicolai


author: Bill Bailey
body: Hello [@Luana Premoli](/t5/user/viewprofilepage/user-id/5184366) . Have you tried beating your users until they comply? ;-)

This is a really tough issue to solve. And I have the same issue of creating nice templates, and just have people hit the "c" key to create a blank page.

I assume you only want it in some spaces, so hard to have some solution that works only in some spaces. So you would have to develop a plugin to do what you want, as hiding elements in the menu is not a great solution since there is still a hot key to create a page. Basically have the plugin intercept the Create button and "c" hot key.

All I can suggested is repeated user training, and then find some way to add social shame to people who fail to comply.

comments: author: Robert Reiner _smartics_
body: Hi [@Bill Bailey](/t5/user/viewprofilepage/user-id/502089)  

On our Confluence server the script I referenced in my answer would also map the 'c'-key to start the wizard. I am not sure if you have use cases in mind where this won't work?

You may also provide this script only in the contexts you like. For instance only active on specific spaces.

Cheers,  
Robert


author: Bill Bailey
body: My point was that there is no native way to do what she wants -- it requires code work (and admin access) to accomplish. So my assumption is that writing javascript and deploying it is more than the OP is probably will to do.

So cool script, but the vast majority of users don't have the ability and access.


author: Robert Reiner _smartics_
body: Sorry, I got it wrong. Thank you for your clarification!


author: Robert Reiner _smartics_
body: Hi [@Luana Premoli](/t5/user/viewprofilepage/user-id/5184366),

If it is only that you want to remove the button from the user interface, you could do this by adding some JavaScript code to your Confluence instance. You would need administrator privileges to do this.

Since both buttons have a unique identifier, it is quite easy to remove the  
quick-create-page-button (the one that produces blank pages) and adjust the create-page-button button (labelled with "..." which opens the template selection dialog). For instance the script [create-with-template.js](https://bitbucket.org/smartics/projectdoc-bookmarklets-and-userscripts/raw/master/src/main/resources/de/smartics/projectdoc/confluence/create-with-template.js) would do this "trick" (here is a [description](https://www.smartics.eu/confluence/x/aIC5C) of what it does). You may want to use this as a basis for your own version.  
If you need to hide the "Blank page" template shown in the template selection dialog, your approach with an additional JavaScript would be similar (see [Hide projectdoc Tools](https://www.smartics.eu/confluence/x/oY2YC) for a description and reference to a script of a similar use case).

In case you do not want to write and integrate JavaScript scripts by yourself, you may want to check out *third party apps* that allow you to hide elements (such as [HideElements for Confluence](https://marketplace.atlassian.com/apps/1211757/hideelements-for-confluence)). Please check if this app meets your requirements.

Cheers,  
Robert  

**Disclaimer** : I am one of the authors of the referenced script. It may be used as part of our commercial product [Userscripts for Confluence](https://marketplace.atlassian.com/apps/1223908/userscripts-for-confluence). The script is licensed under the Apache License (see script header) and therefore can be used without our product free of charge.

comments: author: Luana Premoli
body: Hi [@Robert Reiner _smartics_](/t5/user/viewprofilepage/user-id/853340)

I made the request to the responsible sector here at the company indicating your .js and their response was the following:

> a cursory look at the proposed .js appears to be instance-wide rather than project-specific, at least not without further development which this department does not support.

I don't have enough knowledge to develop the add-on to "filter" by a space.

The space we need to apply this restriction is called LELAS.

Do you have anything that can help us?

Thanks.


author: Robert Reiner _smartics_
body: Hi [@Luana Premoli](/t5/user/viewprofilepage/user-id/5184366),

You are correct. The code in which context the script should apply needs to be added (or is provided by a third-party-app or some browser logic).

I do not know how the administrators are planning to integrate the script. You may need some support by software developers to implement the software according to your company standards, but to figure out the current space is fairly simple.

This [article](https://confluence.atlassian.com/confkb/how-to-hide-elements-in-confluence-using-css-or-javascript-313458894.html) on confluence.atlassian.com explains how to integrate your script:

```
<script type="text/javascript">
  AJS.toInit(function(){
    // Here your code to run
});
</script>
```

In older versions of Confluence accessing the space key is as simple as this (am not sure if this is still supported on the latest versions, but I cannot find any updated documentation the the Atlassian server:

```
AJS.params.spaceKey
```

So the following should work according to the documentation cited above:

```
AJS.toInit(function(){
  if(AJS.params.spaceKey === 'LELAS') {
    // Here the code to run on space LELAS
  }
});
```

In case you are dealing with modules (on newer versions of Confluence if *AJS.params* is not supported on your Confluence instance), you would access the space via the Meta module somewhat like this (I also have the reference for the AJS module in the following snippet in case you need it for your script):

```
require(['ajs', 'confluence/meta'],
function (AJS, META) {
"use strict";

// Shows only how to access the spece key ...

const currentSpaceKey = Meta.get('space-key');

// Here more of your code
 
}
```

**Edit:** Please note that this code, as simple as it looks, requires maintenance in case the Confluence API changes. Even if the "hide function" of the script of this solution would only take effect on the desired space, it still would run on every page of every space. So for instance, if the API access of *AJS.params.spaceKey* is removed from Confluence in the future, this code would no longer work and may negatively influence the experience of users.

Hope this helps to get you started.  
Cheers,  
Robert


author: Luana Premoli
body: Hi [@Robert Reiner _smartics_](/t5/user/viewprofilepage/user-id/853340)

Thanks for your explanations.

Just to confirm, so the code that my confluence admin must inform to remove the default page creation button would look like the link below, correct?

<https://pastecry.pt/kxCNwR#DuaDud%3APenFup7At_Ev1Uf7Gux>

```
AJS.toInit(function(){
 if(AJS.params.spaceKey === 'LELAS') {
      const $quickCreateButton = AJS.$('#quick-create-page-button');
 if ($quickCreateButton.length) {
    $quickCreateButton.hide();
    const $createButton = AJS.$('#create-page-button');
    if ($createButton.length) {
      $createButton.text("Create ...");

      $(document).on('keydown', null, 'c', function () {
        $createButton.click();
      });
     }
  }
});
```

Thanks for yout help


author: Robert Reiner _smartics_
body: Hi [@Luana Premoli](/t5/user/viewprofilepage/user-id/5184366)

it seems to me that one closing bracket is missing.

I strongly recommend that you check this script in a development environment (see [Atlassian SDK](https://developer.atlassian.com/server/framework/atlassian-sdk/)) or test environment (probably provided by your admins) before you give it to your Confluence admins. This will help you to spot typos (like the missing bracket) and other issues. Make sure to test it with the version of Confluence you have in production (because of JavaScript modules I mentioned above).

Also be aware that this script needs to be maintained. Make sure that someone is responsible to check that this script works when your admins update Confluence. Maybe this is checked by your admins, but you should be sure. Please keep in mind that this script most likely (depending on how your admins integrate it) runs for each user of Confluence, not only for users of your space.

Maybe you can talk to your Confluence admins and find a solution that ensures now and in the future that the script works as intended?

Be careful. :-)

Cheers,  
Robert


author: Luana Premoli
body: [@Robert Reiner _smartics_](/t5/user/viewprofilepage/user-id/853340) thanks for your help. =)


author: Srinatha T
body: Hi [@Luana Premoli](/t5/user/viewprofilepage/user-id/5184366) ,

I checked more on this. I see that some users have workaround this problem by using macro [Create from Template Macro](https://confluence.atlassian.com/doc/create-from-template-macro-317196995.html). On any page, you can include this add-on to ensure that users are creating pages from the template that you specify.

I myself have not tried this but should be achievable.

*Thanks,*

*Srinath T*


author: Srinatha T
body: Hi [@Luana Premoli](/t5/user/viewprofilepage/user-id/5184366) ,

Welcome to Atlassian Community.

If you're looking to change the behaviour of the primary **Create** button, then I am afraid this is not possible. There is a feature request for this below:

* [CONFSERVER-53447](https://jira.atlassian.com/browse/CONFSERVER-53447) *Allow to configure behavior of the "Create" button*

You can promote specific templates within individual Spaces. See [Promote templates in the Create dialog](https://confluence.atlassian.com/doc/page-templates-296093785.html#PageTemplates-PromotetemplatesintheCreatedialog) for more details.

*I hope the above info helps. Have a good day!*

*Thanks,*

*Srinath T*


Tags: confluence-server

server