version=pmwiki-2.2.50 ordered=1 urlencoded=1
author=Petko
charset=UTF-8
csum=skin template shouldn't have a %3cmeta/> tag specifying the charset
name=PmWiki.SkinTemplates
rev=59
targets=PmWiki.Skins,PmWiki.LayoutVariables,PmWiki.PageVariables,PmWiki.PageDirectives,PmWiki.Internationalizations,Cookbook.HideSearchBar
text=(:Summary:[[PmWiki/Skin(s)]] templates (.tmpl files):)%0a%25define=box block bgcolor=#f9f9fc border='1px solid #666666' margin=10px padding=5px%25%0aThis page describes the skin template files (.tmpl) that are used to create PmWiki ''skins'', and how PmWiki uses them. As described in the [[skins]] page, a skin is a collection of files that specifies the layout for PmWiki pages. Each skin must include a template file that provides the skeleton for displaying a PmWiki page.%0a%0a!! [[#findingprocessing]]Finding and Processing Templates%0a%0aWhen you set the value of the $Skin variable in a configuration file like @@local/config.php@@, like this%0a-> [@%0a## Use the Foo Skin.%0a$Skin = 'foo';%0a@]%0a%0ait tells PmWiki to search for a skin of that name, and use it. The usual result of the search is for PmWiki to load a template file from the appropriate skin directory. In this example, that would probably be the file @@pub/skins/foo/foo.tmpl@@.%0a%0aThe actual processing that PmWiki goes through to find a template file is important for those who are making complex skins, so its worth mentioning what those steps are:%0a%0a>>rframe width=25pct margin-left:2em font-size:smaller%3c%3c%0a!! [[#security]]Security Note%0aThe default value for @@[=$=]SkinLibDirs@@ has server-side and client-side files stored in the same publicly-accessible directory. That is, @@$SkinDir@@ and @@$SkinDirUrl@@ point to the same place. This is done for convenience (both for the skin user, and the skin writer), but it is not necessary.%0a%0aIt has the side effect that its possible to construct a URL ([[http://www.pmwiki.org/pmwiki/pub/skins/pmwiki/pmwiki.tmpl|like this one]]) that will let you look at the contents of the the @@.tmpl@@ or @@.php@@ files that a skin uses. This is usually not an issue as skin files should not contain any sensitive information.%0a%0aStill, a purist might want to move their @@.tmpl@@ and @@.php@@ files out of the directories that are accessible as URLs, and modify their @@[=$=]SkinLibDirs@@ array to reflect this.%0a>>%3c%3c%0a%0a#When @@$PageTemplateFmt@@ is blank (as it should be), PmWiki gathers the names of all candidate skins. It starts with any action-specific skin that is specified in @@[[LayoutVariables#ActionSkin|$ActionSkin]][$action]@@. Thus, if the current action is 'login', and @@$ActionSkin['login']@@ is @@'Bar'@@, then PmWiki will look for a skin named 'Bar'. %0a%0a#If no skin has been found yet, it looks for the skin(s) named in the @@$Skin@@ variable (which is allowed to be an array) and uses the first skin it can find. If it gets to the end of the list without finding a skin, it issues an error.%0a%0a#To attempt to find a skin, PmWiki first consults the @@[[LayoutVariables#SkinLibDirs|[=$=]SkinLibDirs]]@@ variable to know where to look. Skins consist of server-side files that are loaded by PmWiki (such as .php and .tmpl files) and client-side files (such as .css files and images) that will be requested by the user's browser when they look at a skinned PmWiki page. @@$SkinLibDirs@@ is an array of key/value pairs. The key is a directory to look in for the server-side files, while the corresponding value is a URL that points to the public client-side resources used by the skin. The default value of @@[=$=]SkinLibDirs@@ is:%0a -> [@%0a$SkinLibDirs = array(%0a   "./pub/skins/\$Skin"      => "$PubDirUrl/skins/\$Skin",%0a   "$FarmD/pub/skins/\$Skin" => "$FarmPubDirUrl/skins/\$Skin");%0a@]%0a%0a So, using the above definitions, PmWiki would try to find the skin 'foo' by looking for a directory called @@./pub/skins/foo@@ and then for @@$FarmD/pub/skins/foo@@ (with the value of @@$FarmD@@ replaced by the root server directory for Farm files). The first such directory that was found would be assumed to contain the skin it was looking for. It would then set @@$SkinDir@@ to the name of this directory and @@$SkinDirUrl@@ to the corresponding URL.%0a%0a#Once a valid skin directory has been found, PmWiki starts processing the files in that directory, looking for a @@.php@@ skin file to run. It first looks for one with the same name as the skin. So, if the skin is 'foo', it looks for @@foo.php@@. If no such file is found, it then checks for a file named @@skin.php@@. If one of these @@.php@@ files is found, PmWiki loads and runs it. This allows a skin to define custom markup, or custom configuration parameters. It also allows a skin to choose between which of several different @@.tmpl@@ files to load.%0a%0a To specify which @@.tmpl@@ file to load, simply call @@LoadPageTemplate()@@ inside the skin @@.php@@ file, with the name of the @@.tmpl@@ file to be loaded:%0a%0a -> @@LoadPageTemplate($pagename, "$SkinDir/xyz.tmpl");@@%0a%0a For example, a skin might specify a special template to be used if the action is 'print':%0a%0a -> [@%0aif ($GLOBALS['action'] == 'print')%0a  LoadPageTemplate($pagename, "$SkinDir/print.tmpl");%0a@]%0a%0a When the action is something else, PmWiki will fall back to loading the default @@.tmpl@@ file instead.%0a%0a#If no appropriate @@.php@@ file is found, or if that file doesn't load a template, then PmWiki falls back to looking for a template with the same name as the skin, or, failing that, any @@.tmpl@@ file at all, so long as its the only one in the directory. If it finds one, it will load and process it. If not, it will issue an error.%0a%0a!![[#fileformat]]Template file format%0a%0aA template file is basically an HTML file that also contains variable substitutions (indicated by '$') and special directives embedded in HTML comments.  The following special directives are ''required'' in the template file.  %0a# The directive [@%3c!--PageText-->@] belongs to the %3cbody> section of the HTML document, and tells PmWiki where the main content of each wiki page should be placed.  %0a# The directive [@%3c!--HTMLHeader-->@], which goes somewhere in the %3chead> section of the HTML document.%0a# The directive [@%3c!--HTMLFooter-->@] directive, which typically goes before the final %3c/body> tag and is used by some recipes to insert things at the end of the HTML document. [- %25green%25''Prior to PmWiki 2.2.0 the [@%3c!--HTMLFooter-->@] directive was optional.'' -]%0a%0aWhen PmWiki displays a page, it replaces the directives and variable substitutions with the values appropriate to the current page.  For example, the [@%3c!--PageText-->@] directive is replaced with the page's contents, while any instances of $PageUrl are replaced with the url (address) of the current page.%0a%0a%25note%25 Note: your skin template shouldn't have a %3cmeta/> tag specifying the charset (encoding), as PmWiki adds this tag when needed.%0a%0aThere is a long list of variables available for substitution in pages; some of the%0amost useful include:%0a-> [@%0a$PageUrl         the url of the current page%0a$ScriptUrl       the base url to the pmwiki.php script%0a$Title           the page's title (e.g., "`SkinTemplates")%0a$Titlespaced     the page's title with spaces (e.g., "Skin Templates")%0a$Group           the name of the current group  (e.g., "`PmWiki")%0a$FullName        the page's full name (e.g., "`PmWiki.SkinTemplates")%0a$LastModified    the page's last modification time%0a$PageLogoUrl     the url of a site logo%0a$WikiTitle       the site's title%0a$SkinDirUrl      the url of the skin's folder%0a@]%0a%0aThis last variable, $SkinDirUrl, is particularly useful in templates as it allows the skin designer to refer to other files (such as images or style sheets) in the skin folder without having to know the exact url.%0a%0aThe template is not limited to using the variables listed here; nearly any PHP global variable that begins with a capital letter can be used in a skin template.  [[Page variables]] can also be used in templates.%0a%0a!![[#directives]] Skin directives%0a%0aBesides the required [@%3c!--PageText-->@] and [@%3c!--HTMLHeader-->@] directives, PmWiki provides other built-in directives for generating page output.  It's not necessary to use any of these directives, but they can often add capabilities to a skin %0a%0a:[@%3c!--wiki:Main.SomePage-->@]:%0a:[@%3c!--page:Main.SomePage-->@]:%0a: :The [@%3c!--wiki:Main.SomePage-->@] directive outputs the contents of `Main.SomePage.  $-substitutions are allowed in directives, thus a directive like [@%3c!--wiki:$Group.SomePage-->@] will include "`SomePage" of the current group.  %0a%0a: :If multiple pages are listed in the directive, then only the first available page is used.  Thus [@%3c!--wiki:$Group.SomePage Site.SomePage-->@] will display the contents of `SomePage in the current group if it exists, and `Site.SomePage if it doesn't.  To always display `Site.SomePage, even if $`Group.SomePage exists, use two consecutive [@%3c!--wiki:...-->@] directives.%0a%0a: :The [@%3c!--wiki:...-->@] directive only displays pages for which the browser has read permissions.  The [@%3c!--page:...-->@] directive displays pages even if the browser doesn't have read permission.%0a%0a%0a:[@%3c!--file:somefile.txt-->@]:%0a: :The directive [@%3c!--file:somefile.txt-->@] outputs the contents of another file (on the local filesystem) at the point of the directive.  If the file to be included is a .php script, then the PHP script is executed and its output is sent to the browser.  Like the [@%3c!--wiki:...-->@] directive above, $-substitutions are available to be able to output files based on the current page name or group.%0a%0a:[@%3c!--markup:...-->@]:%0a: :The markup directive processes any text that follows the colon as wiki markup and displays that in the output.  %0a%0a:[@%3c!--function:SomeFunction args-->@]:%0a: :This directive calls a PHP function named "`SomeFunction", passing the current page's name and the text following the function name as arguments.  PHP functions called in this manner are typically defined in a local customization file. Args allows only one argument, which has to be splitted then. [@%3c!--function:SomeFunction arg1 arg2 arg3-->@] generates one parameter "arg1 arg2 arg3". However variables can be used (like $LastModifiedBy).%0a%0a!![[#sections]] Page sections%0a%0aA template file can designate "sections" that are included or excluded from the output based on [[page directives]] or other criteria.  A section always begins with [@%3c!--Page...Fmt-->@] and continues to the next section, the end of the template file, or [@%3c!--/Page...Fmt-->@].  For example, a template can specify a [@%3c!--PageLeftFmt-->@] section that is excluded from the output whenever the [@(:noleft:)@] directive is encountered in the page's contents.  PmWiki's predefined sections (and their corresponding page directives) are:%0a-> [@%0a%3c!--PageHeaderFmt-->          (:noheader:)%0a%3c!--PageFooterFmt-->          (:nofooter:)%0a%3c!--PageTitleFmt-->           (:notitle:)%0a%3c!--PageLeftFmt-->            (:noleft:)%0a%3c!--PageRightFmt-->           (:noright:)%0a%3c!--PageActionFmt-->          (:noaction:)%0a@]%0a%0aSkin designers can define custom sections and markups, but currently all section names in the template must begin with "Page" and end with "Fmt". As mentioned you also have to define the corresponding markup (for example in your config.php) like this: %0a%0a->[@Markup('noxyz', 'directives',  '/\\(:noxyz:\\)/ei',%0a    "SetTmplDisplay('PageXYZFmt',0)");@] %0a%0a!![[#i18n]] Internationalization (i18n)[[#Internationalization]]%0a%0aSkins can also be [[internationaliz(ations)]]ed by using [@$[...]@] substitutions.  Any string placed inside of [@$[...]@] is treated as a "translatable phrase", and the phrase is looked up in the current translation tables for a corresponding output phrase.  If a translation is available, then the translated phrase is substituted at that point, otherwise the original phrase is left intact.%0a%0aFor example, the substitution [@$[Edit]@] will display the current translation of "Edit" if it is known, otherwise it displays "Edit".  Thus, the same template can be used for multiple languages, displaying "Editer" when French translations are loaded, "Bearbeiten" when German translations are loaded, and "Edit" when no translation is available.%0a%0a>>faq%3c%3c [[#faq]]%0a%0aQ: How do I customize the CSS styling of my PmWiki layout?[[#customcss]]%0a%0aA: See [[Skins]] for how to change the default PmWiki skin.  See also [[http://www.pmwiki.org/wiki/Skins/Skins|Skins]], where you will find pre-made templates you can use to customize the appearance of your site.  You can also create a file called ''local.css'' in the ''pub/css/'' directory and add CSS selectors there (this file gets automatically loaded if it exists).  Or, styles can be added directly into a local customization file by using something like:%0a%0a-> [@$HTMLStylesFmt[] = '.foo { color:blue; }';@]%0a%0a%0aQ: Where can the mentioned "translation table" be found for adding translated phrases?%0aA: See [[Internationalizations]].%0a%0aQ: Is it possible to have the edit form in full page width, with no sidebar?%0aA: If the sidebar is marked with [@%3c!--PageLeftFmt-->@], adding [@(:noleft:)@] to Site.EditForm will hide it when a page is edited.%0a%0aQ: Can I easily hide the Home Page title from the homepage?%0aA: Yes, you can use in the wiki page either @@[=(:title Some other title:)=]@@ to change it or @@[=(:notitle:)=]@@ to hide it.%0a%0aQ: Is it possible to hide the Search-Bar in the default PmWiki Skin?%0aA: Yes, please see [[Cookbook:HideSearchBar]].%0a%0a
time=1367442691
