DokuWiki

It's better when it's simple

User Tools

Site Tools


template:twigstarter

Differences

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

Link to this comparison view

Next revision
Previous revision
Both sides next revision
template:twigstarter [2019-05-25 09:57]
andi created
template:twigstarter [2021-11-23 10:56] (current)
andi [Variables and Functions]
Line 1: Line 1:
-====== twigstarter Template ======+====== TwigStarter Template ======
  
 ---- template ---- ---- template ----
Line 5: Line 5:
 author        : Andreas Gohr author        : Andreas Gohr
 email         : andi@splitbrain.org email         : andi@splitbrain.org
-lastupdate_dt : 2019-05-24+lastupdate_dt : 2020-07-07
 compatible    : compatible    :
 depends       : depends       :
Line 11: Line 11:
 similar       : starter similar       : starter
 screenshot_img: # URL to a screenshot (should be a bigger one) screenshot_img: # URL to a screenshot (should be a bigger one)
-tags          : starter, !experimental, twig, sidebar+tags          : starter, twig, sidebar
  
-downloadurl   : https://github.com/splitbrain/dokuwiki-template-sample/zipball/master +downloadurl   : https://github.com/splitbrain/dokuwiki-template-twigstarter/zipball/master 
-bugtracker    : https://github.com/splitbrain/dokuwiki-template-sample/issues +bugtracker    : https://github.com/splitbrain/dokuwiki-template-twigstarter/issues 
-sourcerepo    : https://github.com/splitbrain/dokuwiki-template-sample/+sourcerepo    : https://github.com/splitbrain/dokuwiki-template-twigstarter/
 donationurl   :  donationurl   : 
 ---- ----
Line 22: Line 22:
  
 The template is meant as an alternative to the [[template:starter|Starter Template]]. It has much less code and comments. It's meant for more experienced template developers to quickly get started. The template is meant as an alternative to the [[template:starter|Starter Template]]. It has much less code and comments. It's meant for more experienced template developers to quickly get started.
- 
-Note: this is currently experimental as there are no templates that have been built on top of this, yet. 
  
 ===== Getting started ====== ===== Getting started ======
  
-There are two ways to use this template to create your own.You can either simply copy it and start customizing it, or you can copy only parts of it and make your template depend on the twigstarter template. In the latter case, user will need to install your template **and** the twigstarter template.+There are two ways to use this template to create your own.You can either simply copy it and start customizing it, or you can copy only parts of it and make your template depend on the twigstarter template. In the latter case, users will need to install your template **and** the twigstarter template.
  
 DokuWiki expects three files in a template directory: ''main.php'', ''detail.php'' and ''mediamanager.php''. When you look at these files in twigstarter you will notice that all three files are the same and simply initialize a namespaced TemplateController class defined in ''TemplateController.php''. DokuWiki expects three files in a template directory: ''main.php'', ''detail.php'' and ''mediamanager.php''. When you look at these files in twigstarter you will notice that all three files are the same and simply initialize a namespaced TemplateController class defined in ''TemplateController.php''.
  
-Depending on what way you want to use there are different things to do:+ 
 +> There's also a [[https://www.patreon.com/posts/combining-twig-27328611|blog post]] available giving a bit more background information. 
 + 
 +Depending on what way you want to usethere are different things to do:
  
 ==== TwigStarter Copy ==== ==== TwigStarter Copy ====
Line 39: Line 40:
 ==== TwigStarter Child ==== ==== TwigStarter Child ====
  
-If you want to depend on the original twigstarter template, copy over all files except for+If you want to depend on the original twigstarter template, copy over the following files:
  
-  * ''TemplateController.php'' +  * ''main.php'' 
-  * ''vendor/'' +  * ''detail.php'' 
-  * ''composer.json'' +  * ''mediamanager.php'' 
-  * ''composer.lock'' +  * ''style.ini''
-  * ''templates/''+
  
 Next create your own ''templates'' directory and start writing the templates you want. Next create your own ''templates'' directory and start writing the templates you want.
Line 53: Line 53:
 The twigstarter template comes with a ''style.ini'' that references the ''dokuwiki'' template's styles. This ensures that most of the basic features of the wiki (Mediamanagement, Recent Changes, Admin Screens, etc) are already styled. Since plugins often expect some styles from the default template, this approach also ensures maximum compatibility. The twigstarter template comes with a ''style.ini'' that references the ''dokuwiki'' template's styles. This ensures that most of the basic features of the wiki (Mediamanagement, Recent Changes, Admin Screens, etc) are already styled. Since plugins often expect some styles from the default template, this approach also ensures maximum compatibility.
  
 +You need to add your own styles after the included ones. TwigStarter itself defines absolutely no styles on its own out of the box.
  
 ===== Templating ===== ===== Templating =====
Line 70: Line 71:
 ==== Layout ==== ==== Layout ====
  
-Twig supports [[https://twig.symfony.com/doc/2.x/tags/extends.html|extending]] templates. The example templates provided with twigstarter use this to extend from a commond ''layout.twig'' file. This is basic as possible but should contain all important bits a template needs:+Twig supports [[https://twig.symfony.com/doc/2.x/tags/extends.html|extending]] templates. The example templates provided with twigstarter use this to extend from a common ''layout.twig'' file. This is as basic as possible but should contain all important bits a template needs:
  
   * ''<head>''   * ''<head>''
Line 93: Line 94:
   * The indexer webbug comes at the very end   * The indexer webbug comes at the very end
  
-This is not the most semantic setup, but it would be enough to create a basic template with styling alone. It should give you an easy starting point to create your own, more complex layout.+This is not the most semantic setup, but it would be enough to create a basic template with just styling alone. It should give you an easy starting point to create your own, more complex layout.
  
 ==== Variables and Functions ==== ==== Variables and Functions ====
Line 105: Line 106:
 </code> </code>
  
-In addition, there is an object called ''TPL'' available. This is the ''TemplateController'' and gives you access to it's own public methods. But more importantly it gives you access to all DokuWiki defined functions.+In addition, there is an object called ''TPL'' available. This is the [[https://github.com/splitbrain/dokuwiki-template-twigstarter/blob/master/TemplateController.php|TemplateController]] and gives you access to it's own public methods. Most importantly it also gives you access to all DokuWiki defined functions.
  
 Examples: Examples:
Line 120: Line 121:
  
 Note: Twig escapes by default, when you call functions that return HTML you need to pass them through the ''raw'' filter! Note: Twig escapes by default, when you call functions that return HTML you need to pass them through the ''raw'' filter!
 +
 +==== Custom Controller ====
 +
 +Usually you want some additional PHP code in your template. The easiest way to do so is to create class ''\dokuwiki\template\YOURTEMPLATE\CustomController'' that implements the ''\dokuwiki\template\twigstarter\CustomControllerInterface''. This class will automatically be instantiated and be made available as the variable ''SELF'' in Twig.
 +
  
 ==== Caching and Debugging ==== ==== Caching and Debugging ====
Line 125: Line 131:
 Twig templates are compiled and cached. During development you don't want that. To disable caching, simply enable the [[config:allowdebug]] option. This will also print stack traces when something goes wrong. Twig templates are compiled and cached. During development you don't want that. To disable caching, simply enable the [[config:allowdebug]] option. This will also print stack traces when something goes wrong.
  
 +===== Templates based on TwigStarter =====
 +
 +Most templates that have been made with TwigStarter are not publically available as they have been built for clients at my dayjob. However below is (currently short) list of publically available template based on TwigStarter:
  
 +  * [[template:Notos]] (Child-Theme)
  
template/twigstarter.1558771059.txt.gz · Last modified: 2019-05-25 09:57 by andi