Block creation of pages without template

Luana Premoli April 26, 2023

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

 

5 answers

3 votes
Nicolai Sibler
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.
April 28, 2023

Hi @Luana Premoli ,

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

0 votes
Bill Bailey
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.
April 26, 2023

Hello @Luana Premoli . 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.

Robert Reiner _smartics_
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.
April 27, 2023

Hi @Bill Bailey

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

Bill Bailey
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.
April 29, 2023

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.

Robert Reiner _smartics_
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.
May 1, 2023

Sorry, I got it wrong. Thank you for your clarification!

0 votes
Robert Reiner _smartics_
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.
April 26, 2023

Hi @Luana Premoli,

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  would do this "trick" (here is a description 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 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). 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. The script is licensed under the Apache License (see script header) and therefore can be used without our product free of charge.

Luana Premoli April 28, 2023

Hi @Robert Reiner _smartics_ 

 

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.

Robert Reiner _smartics_
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.
May 1, 2023

Hi @Luana Premoli,

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 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

Luana Premoli May 3, 2023

Hi @Robert Reiner _smartics_ 

 

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 

Robert Reiner _smartics_
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.
May 3, 2023

Hi @Luana Premoli

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) 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

Luana Premoli May 3, 2023

@Robert Reiner _smartics_  thanks for your help. =)

0 votes
Srinatha T
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 26, 2023

Hi @Luana Premoli ,

I checked more on this. I see that some users have workaround this problem by using macro Create from Template Macro. 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 

0 votes
Srinatha T
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 26, 2023

Hi @Luana Premoli ,

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:

You can promote specific templates within individual Spaces. See Promote templates in the Create dialog for more details.

 

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

Thanks,

Srinath T 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events