DokuWiki

It's better when it's simple

User Tools

Site Tools


devel:renderer_plugins

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
devel:renderer_plugins [2020-10-14 17:11] – small grammatical fix Atlas48@gmx.comdevel:renderer_plugins [2023-09-01 22:02] (current) Klap-in
Line 7: Line 7:
 A Renderer Plugin //Example// needs: A Renderer Plugin //Example// needs:
   * class name  ''renderer_plugin_example''   * class name  ''renderer_plugin_example''
-  * which extends [[xref>Doku_Renderer]]((defined in [[xref>inc/parser/renderer.php]])) or one of it's subclasses. +  * which extends [[xref>inc::Doku_Renderer|Doku_Renderer]]((defined in [[xref>inc/parser/renderer.php]])) or one of it's subclasses. 
   * to be stored in a file ''lib/plugins/example/renderer.php''.   * to be stored in a file ''lib/plugins/example/renderer.php''.
 Moreover, a [[plugin_info|plugin.info.txt]] file is needed. For full details of plugins and their files and how to create more renderer components refer to [[plugin file structure]]. Moreover, a [[plugin_info|plugin.info.txt]] file is needed. For full details of plugins and their files and how to create more renderer components refer to [[plugin file structure]].
Line 16: Line 16:
  
 ===Optional implementation=== ===Optional implementation===
-  * **''canRender($format)''** Needs to return true for ''%%$format='xhtml'%%''. This function is needed for a replacement renderer, so DokuWiki knows that it should be displayed in its configuration manager as a xhtml replacement.+  * **''canRender($format)''** Needs to return true for ''%%$format = 'xhtml'%%''. This function is needed for a replacement renderer, so DokuWiki knows that it should be displayed in its configuration manager as a xhtml replacement.
  
  
Line 44: Line 44:
 To make the plugin's export mode accessible to the wiki user, add a button or link somewhere using a [[devel:Syntax Plugins|syntax plugin]] or [[devel:Action Plugins|action plugin]]. To create the correct link you should use the [[xref>exportlink|exportlink()]] function. To make the plugin's export mode accessible to the wiki user, add a button or link somewhere using a [[devel:Syntax Plugins|syntax plugin]] or [[devel:Action Plugins|action plugin]]. To create the correct link you should use the [[xref>exportlink|exportlink()]] function.
  
-When your plugin creates a different output format than ''text/html'', you need to set all needed HTTP headers in the metadata of the page. This is best done in the [[xref>document_start|document_start()]] method of your renderer. Here is an example from the [[plugin:ODT]] plugin (''[[https://github.com/LarsGit223/dokuwiki-plugin-odt/blob/master/renderer/page.php|odt/renderer/page.php]]''):+When your plugin creates a different output format than ''text/html'', you need to set all needed HTTP headers in the metadata of the page. This is best done in the [[xref>document_start|document_start()]] method of your renderer. Here is an example from the [[plugin:ODT]] plugin (''[[https://codesearch.dokuwiki.org/xref/plugin/odt/renderer/page.php|odt/renderer/page.php]]''):
  
 <code php> <code php>
-function document_start() {+public function document_start() {
     ...     ...
     ...     ...
     $filename = noNS($ID) . '.odt';     $filename = noNS($ID) . '.odt';
-    $headers = array(+    $headers = [
         'Content-Type' => 'application/vnd.oasis.opendocument.text',         'Content-Type' => 'application/vnd.oasis.opendocument.text',
         'Content-Disposition' => 'attachment; filename="' . $filename . '";'         'Content-Disposition' => 'attachment; filename="' . $filename . '";'
-    )+    [
-    p_set_metadata($ID,array('format' => array('odt' => $headers) ));+    p_set_metadata($ID, ['format' => ['odt' => $headers]]);
 } }
 </code> </code>
Line 73: Line 73:
  
 <code php> <code php>
-function canRender($format) { +public function canRender($format) { 
-    return ($format=='xhtml');+    return ($format == 'xhtml');
 } }
 </code> </code>
Line 90: Line 90:
  
 When a renderer plugin is disabled or uninstalled, it falls back to the default bundled renderer of the requested output format. When a renderer plugin is disabled or uninstalled, it falls back to the default bundled renderer of the requested output format.
 +
 ===== Further reading ===== ===== Further reading =====
  
devel/renderer_plugins.txt · Last modified: 2023-09-01 22:02 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