diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_makeTemplateFromDocument.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_makeTemplateFromDocument.xml
index 21d9841c8823c21637eebd6eebfbe0dd2988f599..345c702c530b48ea2bdc56c76997ab769419d887 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_makeTemplateFromDocument.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_makeTemplateFromDocument.xml
@@ -53,15 +53,28 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>portal_preferences = context.portal_preferences\n
+            <value> <string>portal = context.getPortalObject()\n
 \n
-preference = portal_preferences.getActivePreference()\n
-if preference is None or preference.getPreferenceState()!=\'enabled\':\n
-  p = portal_preferences.newContent(portal_type=\'Preference\')\n
+preference = portal.portal_preferences.getActivePreference()\n
+if preference is None\\\n
+    or preference.getPreferenceState() != \'enabled\'\\\n
+    or not portal.portal_membership.checkPermission(\n
+      \'Add portal content\', preference):\n
+  p = portal.portal_preferences.newContent(portal_type=\'Preference\')\n
   p.setTitle(\'Document Template Container\')\n
   p.enable()\n
   preference = p\n
 \n
+\n
+# if the preference already contains a template with the same name, making\n
+# another template will replace it\n
+document_title = context.getTitle()\n
+for existing_template in preference.contentValues(\n
+    portal_type=context.getPortalType()):\n
+  if existing_template.getTitle() == document_title:\n
+    preference.manage_delObjects(ids=[existing_template.getId()])\n
+    break\n
+\n
 parent = context.getParentValue()\n
 document_id = context.getId()\n
 cp = parent.manage_copyObjects(ids=[document_id])\n
@@ -115,14 +128,16 @@ return context.Base_redirect(form_id,\n
                             <string>kw</string>
                             <string>_getattr_</string>
                             <string>context</string>
-                            <string>portal_preferences</string>
+                            <string>portal</string>
                             <string>preference</string>
                             <string>None</string>
                             <string>p</string>
+                            <string>document_title</string>
+                            <string>_getiter_</string>
+                            <string>existing_template</string>
                             <string>parent</string>
                             <string>document_id</string>
                             <string>cp</string>
-                            <string>_getiter_</string>
                             <string>paste_info</string>
                             <string>getattr</string>
                             <string>_getitem_</string>
diff --git a/product/ERP5/bootstrap/erp5_core/bt/revision b/product/ERP5/bootstrap/erp5_core/bt/revision
index f14fd467eb557b612a21b1160aebe2072e2dd585..ee8a369bd0f51a908d123e9914684a1e35e2b132 100644
--- a/product/ERP5/bootstrap/erp5_core/bt/revision
+++ b/product/ERP5/bootstrap/erp5_core/bt/revision
@@ -1 +1 @@
-1560
\ No newline at end of file
+1561
\ No newline at end of file