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 [2020-05-18 09:22]
andi [TwigStarter Template]
template:twigstarter [2021-11-23 10:56] (current)
andi [Variables and Functions]
Line 5: Line 5:
 author        : Andreas Gohr author        : Andreas Gohr
 email         : andi@splitbrain.org email         : andi@splitbrain.org
-lastupdate_dt : 2019-07-10+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-twigstarter/zipball/master downloadurl   : https://github.com/splitbrain/dokuwiki-template-twigstarter/zipball/master
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 public templates that have been built on top of this, yet. My personal site's template however uses the child approach described below. 
  
 ===== 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 71: 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 common ''layout.twig'' file. This is aa 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 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.
 +
  
 ==== Caching and Debugging ==== ==== Caching and Debugging ====
Line 126: 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.1589786545.txt.gz · Last modified: 2020-05-18 09:22 by andi