Sphinx Documentation Viewer Plugin

Classification

restdoc

Version

main

Language

en

Description

Seamlessly embeds Sphinx/reStructuredText-based documentation into your TYPO3 website. Instead of publishing your various manual, in-house documents, guides, references, ... solely as PDF, render them as JSON and use this extension to show them as part of your website to enhance the overall user experience and Search Engine Optimization (SEO). Lets you merge the chapter structure with the breadcrumb menu and much more. Documentation styles automatically inherit from your corporate design.

Keywords

reStructuredText, sphinx-doc, documentation

Copyright

2012-2024

Author

Xavier Perseguers

Email

xavier@causal.ch

License

This document is published under the Open Publication License available from http://www.opencontent.org/openpub/

Rendered

Tue, 22 Jul 2025 19:08:56 +0000

The content of this document is related to TYPO3, a GNU/GPL CMS/Framework available from www.typo3.org.

Table of Contents

Introduction

What does it do?

This extension lets you build documentation projects written with Sphinx (the Python Documentation Generator used by the TYPO3 documentation team for all official documentation) from within the TYPO3 Backend:

|

The name of this extension comes from the underlying markup language used by Sphinx. In fact, Sphinx uses reStructuredText (commonly abbreviated as reST) as its markup language.

Sphinx was originally created for the Python documentation and a few features are worth highlighting:

  • Output formats: HTML, JSON (a derivate from HTML this extension is relying on), LaTeX (for printable PDF versions), plain text, ...
  • Extensive cross-references: semantic markup and automatic links for citations, glossary terms and similar pieces of information. For instance, the official TYPO3 documentation provides resources to cross-link from your own documentation to virtually any chapter or section of any TYPO3 documentation. Please consult page Tips and Tricks in the TYPO3 wiki for more information.
  • Hierarchical structure: easy definition of a document tree, with automatic links to siblings, parents and children
  • Automatic index: general index of terms used in your documentation
  • Extensions: the tool lets you extend it with your own modules

And this extension?

The "Sphinx way" of publishing a reST documentation to the Web is to generate either a standalone HTML website (or single page) or a PDF. The drawback of using a standalone HTML website is that it is extremely tedious to adapt the base templates provided by Sphinx to your needs to get something visually comparable to your website's design you try to look like.

Fortunately, Sphinx lets you generate your documentation as JSON files which are basically the HTML output without any layout.

This extension uses the JSON content parts and lets you freely place them in your TYPO3 website, where they belong in the overall design (e.g., the table of contents as part of your navigation menu, the documentation itself as main content, ...). The integration of your reST documentation is not only much more effective but is also better from a SEO point of view as your documentation is seen as real content of your TYPO3 website.

How to start?

If you already have a Sphinx documentation project at hand, generate a JSON output with make json instead of make html, copy the whole output directory to your website, place a restdoc plugin on your page and you're done!

If you are new to Sphinx, reStructuredText and currently write your documentation with one of the common word processors (OpenOffice Writer, MS Word, ...), don't worry! The TYPO3 documentation team and a few other passionate persons are maintaining tutorials and tips and tricks in the TYPO3 wiki.

Screenshots

|plugin_options|

Requirements

You need a documentation written in reStructuredText and as a Sphinx project. Please visit https://wiki.typo3.org/ReST for further information. You may consider using TYPO3 extension Sphinx to easily set up your environment and work on your own documentation.

The main documentation file should be named Index.rst (to match the convention of the TYPO3 Documentation Team). If you choose to name it "index.rst" instead (lower case), or want to use another arbitrary name, make sure to update the default TypoScript settings accordingly.

Generating the documentation as JSON

When kickstarting a project, Sphinx creates a Makefile with different output. Generating your documentation is just a matter of running:

$ cd /path/to/documentation
$ make json
Copied!

The documentation will be created in a json directory within the build (or _build) directory. This json directory is what should be published to your TYPO3 website, typically somewhere within fileadmin/.

Plugin options

The plugin options let you choose whether the content of the file (BODY), the table of contents (TOC), the master table of contents (MASTER_TOC), the quick navigation (QUICK_NAVIGATION) or a list of references (REFERENCES) should be generated. The table of contents is in fact a contextual menu for the current chapter, aka a "mini-toc" whereas the quick navigation shows previous/next links, typically after the content of the file, in a footer.

|plugin_options|

Search Form

A search form may be generated with option (SEARCH).

Installing the extension

There are a few steps necessary to install the Sphinx Documentation Viewer Plugin extension. If you have installed other extensions in the past, you will run into little new here.

Install the extension from Extension Manager

The Sphinx Documentation Viewer Plugin extension can ben installed through the typical TYPO3 installation process using the Extension Manager.

The Extension Manager will create a new table in your database. This table is used to store references to the chapters in the context of the plugin and is used to both generate the menu of recent updates in your documentation and to integrate the structure of your documentation within your website's sitemap.

Configure Routing

In order to get pretty URL, you are advised to edit file config/sites/*/config.yaml and extend it like that:

routeEnhancers:
  Restdoc:
    type: RestdocPlugin
    limitToPages: [1]
Copied!

You should naturally adapt limitToPages to the pages where the restdoc plugin is located. If you don't, the plugin will determine that dynamically but this will have a small performance penalty. You may figure out the list by running this SQL query:

SELECT
    DISTINCT pid
FROM
    tt_content
WHERE
    CType = 'list'
    AND list_type = 'restdoc_pi1'
    AND sys_language_uid = 0 AND deleted = 0;
Copied!
.. info::

This will default to extend your configuration like that:

routeEnhancers:
  Restdoc:
    type: RestdocPlugin
    limitToPages: [1]
    routePath: '/{doc}'
    requirements:
      doc: '.+'
Copied!

Naturally you may override the routePath and corresponding requirements to fit your own special use case, if needed.

TypoScript configuration

In order for this extension to be usable, make sure to include the static template that is provided with this extension ("Sphinx Documentation Viewer: Base").

The TypoScript configuration should be generic enough to let you fine tune the rendering process to fit your needs. As an example, for a project I changed the rendering of the images to:

  • Add an overlay shown when the mouse enters pictures with the ALT label
  • Add a fancybox (lightbox) for the image whenever it got resized, but not when the image was not resized (does not make sense to show a lightbox with the very same image...
  • Do not do those changes for small inline images (say smaller than 100px width)

This is just a matter of playing with TypoScript, something you should love anyway as a TYPO3 integrator. Please note that the extension comes with a directory containing TypoScript snippets.

Available modes for the plugin

When integrating the plugin with TypoScript, additional modes of operations are available. These are:

TOC
Generates a table of contents
MASTER_TOC
Generates the master table of contents
RECENT
Renders a list of chapters updated recently
BODY
Generates the documentation itself
TITLE
Returns the current chapter's title
QUICK_NAVIGATION
Generates a quick navigation with "previous", "next", "home", ...
BREADCRUMB
Generates a breadcrumb menu for the current chapter
REFERENCES
Generates a list of references within the whole documentation
FILENAME
Returns the name of the .fjson being rendered
SEARCH
Generates a search form

Additional Content Object

This extension registers an additional content object to let you access meta-information from your documentation. Example:

10 = REST_METADATA
10 {
    path = {$plugin.tx_restdoc.path}
    field = copyright
    noTrimWrap = |Copyright © ||
}
Copied!

Please read next chapter for a list of available fields.

plugin.tx_restdoc_pi1

Properties

Property details

path

plugin.tx_restdoc_pi1.path = string

Path to the root directory of the documentation.

defaultFile

plugin.tx_restdoc_pi1.defaultFile = string

Default file (main file).

mode

plugin.tx_restdoc_pi1.mode = string

Either BODY, TOC, RECENT, TITLE, QUICK_NAVIGATION, BREADCRUMB, REFERENCES, FILENAME or SEARCH to setup the plugin from TypoScript.

rootPage

plugin.tx_restdoc_pi1.rootPage = integer

UID of the page showing the documentation. This setting is used when mode = SEARCH to link back to the documentation from search results.

documentStructureMaxDocuments

plugin.tx_restdoc_pi1.documentStructureMaxDocuments = integer

Maximal number of documents to be processed at once when generating the documentation's structure.

advertiseSphinx

plugin.tx_restdoc_pi1.advertiseSphinx = boolean

Whether header JS block should be generated to advertise Sphinx to plugins such as Wappalizer.

addHeadPagination

plugin.tx_restdoc_pi1.addHeadPagination = boolean

Whether pagination links should be added to the HEAD part. See Google's Webmaster Central Blog for additional information.

publishSources

plugin.tx_restdoc_pi1.publishSources = boolean

If active, the sources of your documentation (content of directory _sources/ will be published. Please note that this flag should be set if you want to show a context of where a search term was found.

baseWrap

plugin.tx_restdoc_pi1.baseWrap = stdWrap

Override the default wrap for the plugin:

<div class="tx-restdoc-pi1">
    ...
</div>
Copied!

plugin.tx_restdoc_pi1.setup

Properties

Property Data type stdWrap Default
BODY.image.renderObj t3tsref:cobjects no see setup.txt
TOC.renderObj t3tsref:cobjects no see setup.txt
MASTER_TOC.renderObj t3tsref:cobjects no see setup.txt
RECENT.renderObj t3tsref:cobjects no see setup.txt
QUICK_NAVIGATION.renderObj t3tsref:cobjects no see setup.txt
BREADCRUMB.renderObj t3tsref:cobjects no see setup.txt
REFERENCES.renderObj t3tsref:cobjects no see setup.txt

Property details

BODY.image.renderObj

plugin.tx_restdoc_pi1.setup.BODY.image.renderObj = t3tsref:cobjects

Setup to render the images within the documentation.

TOC.renderObj

plugin.tx_restdoc_pi1.setup.TOC.renderObj = t3tsref:cobjects

Setup to render the table of contents of the documentation.

MASTER_TOC.renderObj

plugin.tx_restdoc_pi1.setup.MASTER_TOC.renderObj = t3tsref:cobjects

Setup to render the master table of contents of the documentation.

RECENT.renderObj

plugin.tx_restdoc_pi1.setup.RECENT.renderObj = t3tsref:cobjects

Setup to render the list of chapters updated recently.

QUICK_NAVIGATION.renderObj

plugin.tx_restdoc_pi1.setup.QUICK_NAVIGATION.renderObj = t3tsref:cobjects

Setup to render the quick navigation (previous/next links).

REFERENCES.renderObj

plugin.tx_restdoc_pi1.setup.REFERENCES.renderObj = t3tsref:cobjects

Setup to render the list of references.

REST_METADATA

Properties

Property Data type stdWrap Default
path string yes empty
(stdWrap properties) stdWrap property    

Property details

path

REST_METADATA.path = string

Path to the root directory of the documentation.

(stdWrap properties)

REST_METADATA.<stdWrap property> = stdWrap property

Available fields:

  • shorttitle
  • copyright
  • project
  • version
  • release
  • sphinx_version
  • ...

Example

10 = REST_METADATA
10.field = copyright
Copied!

Usage with EXT:bootstrap_package

This section describes how to extend the default page TypoScript from the TYPO3 extension bootstrap_package in order to extend the breadcrumb menu generated as a FLUIDTEMPLATE dataProcessor and append the breadcrumb menu from the documentation itself.

You may naturally inspire from this even if you are not using the bootstrap_package extension.

The idea is to create an extension template on the page where you put the Sphinx Documentation Viewer Plugin.

Constants

# Configure the path for the documentation (here: fileadmin/documentation/en/)
plugin.tx_restdoc.path = t3://folder?storage=1&identifier=%2Fdocumentation%2Fen%2F
Copied!

Setup

# Needed to initialize the plugin without actually outputing anything and
# be able to generate a full breadcrumb menu as dataProcessing (see below)
page.1 < plugin.tx_restdoc_pi1
page.1 {
  baseWrap >
  baseWrap.wrap = |
}

# Replace the standard breadcrumb menu from bootstrap_package with our own
# one, containing the full rootline and documentation's breadcrumb menu
page.10.dataProcessing.30 {
  special = userfunction
  special.userFunc = Causal\Restdoc\Controller\Pi1\Pi1Controller->makeMenuArray
  special.userFunc.type = rootline_breadcrumb
}
Copied!

Development

This chapter describes some internals of the restdoc extension to let you extend it easily.

Hooks

Extending even more

In case you want to really extend the output, you may want to take a whole different approach and only take advantage of the internal Sphinx JSON reader but create the plugin on your own, possibly using Extbase instead of the plugin we provide.

In that case, be sure to have a look at this project to inspire from: https://github.com/xperseguers/t3ext-docstypo3org

renderHook

This hook can be used to post-process the general plugin's output before being wrapped by either your custom TypoScript processing or the standard base class:

<div class="tx-restdoc-pi1">
    ...
</div>
Copied!

Registration

You should register your class in:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['restdoc']['renderHook']
Copied!

Expected method

Your hook should implement a method postProcessOutput() of the form

public function postProcessOutput(array $params)
{
    // Custom code
}
Copied!

Parameters

$params is an array with following keys:

mode
The plugin's mode
documentRoot
Absolute path to the documentation's root
document
Relative path to the current document
output
Reference to the output of the plugin, may thus be changed within your hook
config
Configuration of the plugin
pObj
A reference to the current \Causal\Restdoc\Controller\Pi1\Pi1Controller instance

makeMenuArrayHook

This hook can be used to post-process the menu entries when generating a menu in TypoScript (general menu, previous/next page, breadcrumb menu, updated chapters).

Registration

You should register your class in:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['restdoc']['makeMenuArrayHook']
Copied!

Expected method

Your hook should implement a method postProcessTOC() of the form

public function postProcessTOC(array $params)
{
    // Custom code
}
Copied!

Parameters

$params is an array with following keys:

documentRoot
Absolute path to the documentation's root
document
Relative path to the current document
data
A reference to an array of menu entries compatible with the various *MENU content objects, may thus be changed within your hook
config
Configuration of the plugin
pObj
A reference to the current \Causal\Restdoc\Controller\Pi1\Pi1Controller instance

quickNavigationHook

This hook can be used to post-process the quick navigation items.

Registration

You should register your class in:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['restdoc']['quickNavigationHook']
Copied!

Expected method

Your hook should implement a method postProcessQUICK_NAVIGATION() of the form

public function postProcessQUICK_NAVIGATION(array $params)
{
    // Custom code
}
Copied!

Parameters

$params is an array with following keys:

documentRoot
Absolute path to the documentation's root
document
Relative path to the current document
data

A reference to an array with the various links, may thus be changed within your hook. Available keys:

  • home_title / home_uri / home_uri_absolute
  • previous_title / previous_uri / previous_uri_absolute
  • next_title / next_uri / next_uri_absolute
  • parent_title / parent_uri / parent_uri_absolute
  • index_title / index_uri / index_uri_absolute
  • has_previous / has_next / has_parent / has_index
config
Configuration of the plugin
pObj
A reference to the current \Causal\Restdoc\Controller\Pi1\Pi1Controller instance

searchFormHook

This hook can be used to pre-process the search form.

Registration

You should register your class in:

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['restdoc']['searchFormHook']
Copied!

Expected method

Your hook should implement a method preProcessSEARCH() of the form

public function preProcessSEARCH(array $params)
{
    // Custom code
}
Copied!

Parameters

$params is an array with following keys:

config

A reference to the configuration of the search form:

  • jsLibs: Array of JavaScript libraries to be loaded (underscore.js, doctools.js, searchtools.js)
  • jsInline: Inline JavaScript code (loading the index resource)
  • advertiseSphinx: Whether to advertise Sphinx (standard inline JavaScript code needed by searchtools.js, thus default to TRUE)
pObj
A reference to the current \Causal\Restdoc\Controller\Pi1\Pi1Controller instance

Known problems

  • Only FAL LocalStorage has been implemented and tested, meaning code will need to be adapted in order to deal with other types of remote storage.

To-Do list

This project evolves and matures as new use cases pop up. You would like to see a killer feature? You have thought of better user experience? Great!

|finger|

Translation

Another very easy way to contribute to the success of this extension is to translate it on the Crowdin translation server; other users will thank you much.

ChangeLog

The following is a very high level overview of the changes in this extension. For more details, read the online log.

Version Changes
2.1.0 Compatibility with TYPO3 v9 to v11
2.0.0 Compatibility with TYPO3 v8 to v11
1.7.x Post-processing of content with SphinxJson
1.6.x
  • Compatibility with TYPO3 6.2 - 8.x
  • Compatibility with PHP 7
1.5.x Extended support for RealURL
1.4.x Compatibility with TYPO3 6.2 - 7.x
1.3.x
  • Refactoring of the JSON reader
  • Compatible with official TYPO3 manuals
1.2.x
  • Compatible with TYPO3 6.x (FAL)
  • Support for metadata and Sphinx advertisement (Wappalizer)
  • Built-in Sphinx search within the documentation
1.1.x Support for index and breadcrumb menu
1.0.x Better integration with TypoScript, extension is considered stable
0.1.0 First release on TER