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

Both sides previous revisionPrevious revision
Next revision
Previous revision
Both sides next revision
template:twigstarter [2021-07-01 14:58]
andi
template:twigstarter [2021-11-23 10:56] (current)
andi [Variables and Functions]
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: There are currently no public templates that have been built on top of this, yet. My personal site's template however uses the child approach described below. The template has been used to implement templates for multiple clients at my dayjob. 
  
 ===== Getting started ====== ===== Getting started ======
Line 30: Line 28:
  
 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''.
 +
 +
 +> 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 use, there are different things to do: Depending on what way you want to use, there are different things to do:
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 121: 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. 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 128: 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.1625144315.txt.gz · Last modified: 2021-07-01 14:58 by andi