DokuWiki

It's better when it's simple

User Tools

Site Tools


namespace_templates

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
namespace_templates [2012-12-06 15:14] – [Replacement patterns] Klap-innamespace_templates [2024-05-03 09:02] (current) – [Template files] differentiated zweihorn
Line 1: Line 1:
 ====== Namespace Templates ====== ====== Namespace Templates ======
  
-Sometime you might want to have every page in a certain namespace based on a common skeleton. For example, in the ''address'' namespace you could have an already prepared table, which only needs to be filled with data. This can be easily achieved with so called "namespace templates"+Dokuwiki supports scaffolding. Sometimes you might want to have every page in a certain namespace based on a common skeleton. For example, in the ''address'' namespace you could have an already prepared table, which only needs to be filled with data. This can be easily achieved with so called "namespace templates".
  
-When a page is created, [[DokuWiki]] looks up whether a template files exists and it shows it within the editor window. The templates therefore are .txt files and should contain wiki markup.+When a page is created, [[DokuWiki]] looks up whether a template file exists and it shows it within the editor window. The templates therefore are .txt files and should contain wiki markup.
  
 ===== Template files ===== ===== Template files =====
-Two kinds of template files can be used : 
  
-  * ''_template.txt'', which are used in the current namespace. +Two kinds of template files can be used:
-  * ''%%__%%template.txt'' (two leading underscores), which work as the normal ''_template.txt'' files apart from the fact they are used in all namespaces below as well (they are inherited).+
  
-One way to create the template file is to+  * ''_template.txt'', which will be used in the current namespace (but not below). 
 +  * ''%%__%%template.txt'' (note the two leading underscores), will cover the current namespace and all namespaces below as well (thus this kind of template will be inherited).
  
-  * use the wiki to save a page with the content that you want to use as a template into the appropriate namespace +If both (normal and inherited) templates are present in the same namespace, the normal ''_template.txt'' will take precedence when a new page is createdThis allows the pages of the top namespace to be differentiated from all pages of any sub-namespaces inherited below, which could become quite handy.
-  * use FTP or WebDAV to make a copy of it in the same folder and rename itthen +
-  * use the wiki to delete the original page.((These changes only apply to new pages that you create in the namespace.))+
  
 +**NOTE:** Any changes to a.m. template files will //only effect newly created pages// and existing pages are always left untouched.
 +
 +One way to create the template file is to:
 +
 +  - use the wiki to save a page with the content that you want to use as a template into the appropriate namespace
 +  - use FTP or WebDAV to rename it as _template.txt
 +
 +However, one should prefer the [[plugin:TemplatePagename]] Plugin if possible (see explanations below).
 ===== Syntax ===== ===== Syntax =====
 The content of the file is just standard [[wiki:syntax|wiki markup]]. The content of the file is just standard [[wiki:syntax|wiki markup]].
Line 23: Line 28:
 Inside of the file, you may also use some replacement patterns to make the template a little more dynamic. Inside of the file, you may also use some replacement patterns to make the template a little more dynamic.
  
-^ @ID@     | full ID of the page                                                                    | +^ @ID@              | full ID of the page                                                                    | 
-^ @NS@     | namespace of the page                                                                  | +^ @NS@              | namespace of the page                                                                  
-^ @PAGE@   | page name (ID without namespace and underscores replaced by spaces)                    | +^ @CURNS@           | last part of the namespace of the page                                                 | 
-^ @!PAGE@  | same as above but with the first character uppercased                                  | +^ @!CURNS@          | same as above but with the first character uppercased                                  | 
-^ @!!PAGE@ | same as above but with the first character of all words uppercased                     | +^ @!!CURNS@         | same as above but with the first character of all words uppercased                     | 
-^ @!PAGE!@ | same as above but with all characters uppercased                                       | +^ @!CURNS!@         | same as above but with all characters uppercased                                       
-^ @FILE@   | page name (ID without namespace, underscores kept as is)                               | +^ @PAGE@            | page name (ID without namespace and underscores replaced by spaces)                    | 
-^ @!FILE@  | same as above but with the first character uppercased                                  | +^ @!PAGE@           | same as above but with the first character uppercased                                  | 
-^ @!FILE!@ | same as above but with all characters uppercased                                       | +^ @!!PAGE@          | same as above but with the first character of all words uppercased                     | 
-^ @USER@   | ID of user who is creating the page                                                    | +^ @!PAGE!@          | same as above but with all characters uppercased                                       | 
-^ @NAME@   | name of user who is creating the page                                                  | +^ @FILE@            | page name (ID without namespace, underscores kept as is)                               | 
-^ @MAIL@   | mail address of user who is creating the page                                          | +^ @!FILE@           | same as above but with the first character uppercased                                  | 
-^ @DATE@   | date and time when edit session started                                                | +^ @!FILE!@          | same as above but with all characters uppercased                                       | 
-^ %a %d-%m-%y etc. | e.g. Thu 06-12-12. [[phpfn>Strftime]] placeholders are replaced by page creation time | +^ @USER@            | ID of user who is creating the page                                                    | 
-^ %%       | a literal ''%'' character appears in your template                                     |+^ @NAME@            | name of user who is creating the page                                                  | 
 +^ @MAIL@            | mail address of user who is creating the page                                          | 
 +^ @DATE@            | date and time when edit session started                                                | 
 +^ %a %d-%m-%y etc.  | e.g. Thu 06-12-12. [[phpfn>strftime]] placeholders are replaced by page creation time  
 +^ %%                | a literal ''%'' character appears in your template                                     |
  
-In addition you may also use any [[phpfn>strftime]] placeholder to insert the time of page creation in any format you like. If you want to use a literal ''%'' character in your template you need to double it. 
-===== Editing templates ===== 
  
-You can't edit the ''_template.txt'' through DokuWiki -- only someone who can edit the files inside the DokuWiki folders (usually an administrator using FTP or WebDAV) can. There are three ways to accomplish this, though:  +===== Still editing templates via wiki===== 
-  * one involving setting up symbolic links once,   + 
-  * one involving a code change  +You can't edit the ''_template.txt'' through DokuWiki (only someone who can edit the files inside the filesystem folders (usually an administrator using FTP or WebDAV) can modify these files). There are three ways to accomplish this, though:  
-  * or the easiest is using plugin that change the default behavior.+  * the easiest is using the [[plugin:TemplatePagename]] plugin which let you change the default templatenames ''<nowiki>_template</nowiki>'' and ''<nowiki>__template</nowiki>'' into another nameE.g. ''c_template'' and ''i_template''. These files are considered normal editable wikipages because they don't start with an underscore. 
 +  * or by setting up through symbolic links  
  
 ==== Editable templates through symbolic links ==== ==== Editable templates through symbolic links ====
 +//**NOTE: This section contains instructions for use on a Linux server and will not work on a Windows system.**//
  
-This way, you can store your templates in a special namespace. By making a symlink to them you can use the template. You can also choose to make a template non-editable by not using a symlink.+This way, you can store your templates in a special namespace, and make symlinks for DokuWiki to find them. You can also choose to make a specific template non-editable by removing its particular symlink.
  
   - Create a namespace called "templates", or something similar.   - Create a namespace called "templates", or something similar.
-  - In this namespace, create a page for each [[:namespace_templates | Namespace Template]] that you wish to be available.+  - In this namespace, create a page for each [[:namespace_templates | Namespace Template]] that you wish to be editable.
   - Follow the instructions given above, but make _template.txt a hard link ((soft links seem not to work, but see the note about FollowSymLinks below)) to the correct page under your templates namespace.  You now have a template that can be modified easily via the wiki interface.   - Follow the instructions given above, but make _template.txt a hard link ((soft links seem not to work, but see the note about FollowSymLinks below)) to the correct page under your templates namespace.  You now have a template that can be modified easily via the wiki interface.
  
-Another way is creating symlinks in the folder itself. Thus you create a ''template.txt'' which is a symbolic link to the ''_template.txt'', in it's own namespace.+Another way is to create symlinks in the folder itself. Thus you create a ''template.txt'' which is a symbolic link to the ''_template.txt'', in it's own namespace.
  
   cd /var/www/html/dokuwiki/data/pages/namespace/something   cd /var/www/html/dokuwiki/data/pages/namespace/something
   ln -s _template.txt template.txt   ln -s _template.txt template.txt
      
-For these softlinks works eventually the webserver needs the FollowSymLinks option set on the directory(tree). +For these softlinks to work, you might need the FollowSymLinks option set for this directory in your webserver's configuration.
- +
  
-==== Editable templates for all users  ==== +//**NOTE: This section contains instructions for use on a Windows server and will not work on a Linux system.**//
- +
-This way, all your templates will be editable by anybody with write access. It's changing hardcode the filename the source is looking for. +
- +
-  - Change the default template name to "template.txt" (or aaa_template.txt) at around line 817 ''inc/common.php'' ((Lines 811 and 812 in version 2009-02-14)).  +
-  - Now any user with write access in the namespace can create a page called "template" in that namespace which will serve as the template. +
-  Note: This method has the advantage that new templates will immediately be recognized. This may not be the case with the other methods (adding files or symlinks manually into the DokuWiki folders).+
  
 +Open up command prompt (cmd.exe) on the server, and browse to the location you with there to be a template. Use the MKLINK command to create a symbolic link.
  
 +  cd c:\inetpub\wiki\data\pages\namespace\something
 +  mklink template.txt _template.txt
  
 ===== Plugins ===== ===== Plugins =====
 +
 Additional template features are implemented by plugins. Additional template features are implemented by plugins.
 +
 +  * [[plugin:TemplatePagename]] Plugin can change the names of ''_template'' and ''__template'' in your choice via configuration manager. Has as defaults respectively ''c_template'' and ''i_template''. This plugin will let you choose normal wiki pages as template so that they are editable via the wiki interface.
  
   * [[plugin:TemplateByName]] Plugin extends available templates with   * [[plugin:TemplateByName]] Plugin extends available templates with
Line 80: Line 88:
     * ''~yournamespace.txt'' for all pages in the subnamespace named ''yournamespace''     * ''~yournamespace.txt'' for all pages in the subnamespace named ''yournamespace''
     * and variants for deeper namespaces too and some other templates e.g. for ''start'' pages.     * and variants for deeper namespaces too and some other templates e.g. for ''start'' pages.
 +All these plugins are only editable via the file system.
  
-  * [[plugin:NewPageTemplate]] Plugin adds an url parameter that define which existing page from the wiki is loaded as template. Every page allowed by ACL is available.  +  * [[plugin:NewPageTemplate]] Plugin adds a URL parameter that defines which existing page from the wiki is loaded as the template. Every page allowed by ACL is available. 
- +
-  * [[plugin:TemplatePagename]] Plugin can change the names of ''_template'' and ''__template'' in your choice via configuration manager. Has as defaults respectively ''c_template'' and ''i_template''+
  
   * [[plugin:Snippets]] Plugin adds a button to the editor toolbar which allows to easily insert templates while editing a page. The shown templates needs to be list on one page, default ''snippets''.   * [[plugin:Snippets]] Plugin adds a button to the editor toolbar which allows to easily insert templates while editing a page. The shown templates needs to be list on one page, default ''snippets''.
  
-Some of the plugins are conflicting. +  * [[plugin:Headerfooter]] Plugin adds header text or footer text to pages only when they are displayed.
  
-==== @GROUPS@ support ==== +==== Troubleshooting ====
-It may be interesting to have support for the ''@GROUPS@'' keyword to extend to the group list of the user creating the page (e.g. to specify a set of tags on a user's home page). The following patch implements it.+
  
-<code unidiff> +ProblemAn unexpected error occurs "no timestamp" when server (Linux Ubuntu) cannot write the directory ''/dokuwiki/data/pages/namespace''. This might happenwhen the namespace directory is created by the admin as ''<root>'' in order to put the namespace template file in ''/dokuwiki/data/pages/namespace/'', before creating the first page.
-Indexdokuwiki-2009-02-14/inc/common.php +
-=================================================================== +
---- dokuwiki-2009-02-14.orig/inc/common.php    2009-11-19 11:58:41.000000000 +0100 +
-+++ dokuwiki-2009-02-14/inc/common.php 2010-01-05 10:17:35.000000000 +0100 +
-@@ -840,6 +840,7 @@ +
-                         '@USER@', +
-                         '@NAME@'+
-                         '@MAIL@'+
-+                        '@GROUPS@'+
-                         '@DATE@', +
-                      ), +
-                      array( +
-@@ -855,6 +856,7 @@ +
-                         $_SERVER['REMOTE_USER'], +
-                         $INFO['userinfo']['name'], +
-                         $INFO['userinfo']['mail'], +
-+                        implode(" ", $INFO['userinfo']['grps']), +
-                         $conf['dformat'], +
-                      ), $tpl); +
- +
  
-</code>+1. Solution: Before establishing the hidden template file, first create a dummy page via the DokuWiki GUI, like so: ''yourserver/doku.php?id=namespace:dummy&do=edit''. This allows DokuWiki to create the namespace directory under own control and assures full write permissions for DokuWiki on the created directory.
  
- --- //[[shtrom-doku@ssji.net|Olivier Mehani]] 2010/01/05 10:19//+2. Solution: The admin ''<root>'' should be able to change //owner and group// settings through the [[https://askubuntu.com/a/6727|chown command]] (e.g., ''chown www-data:www-data /dokuwiki/data/pages/namespace/'' on CLI) and in the first place should establish new directories and files with ''owner:group'' settings applicable to the DokuWiki installation anyway.
namespace_templates.1354803246.txt.gz · Last modified: 2012-12-06 15:14 by Klap-in

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki