View Source Plugin
The View Source Plugin is for Grav CMS and allows you to display the raw header and Markdown for a given page
Installing the View Source plugin can be done in one of two ways. The GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.
GPM Installation (Preferred)
The simplest way to install this plugin is via the Grav Package Manager (GPM) through your system's terminal (also called the command line). From the root of your Grav install type:
bin/gpm install view-source
This will install the View Source plugin into your
/user/plugins directory within Grav. Its files can be found under
To install this plugin, just download the zip version of this repository and unzip it under
/your/site/grav/user/plugins. Then, rename the folder to
view-source. You can find these files on GitHub or via GetGrav.org.
You should now have all the plugin files under
Before configuring this plugin, you should copy the
user/config/plugins/view-source.yaml and only edit that copy.
Here is the default configuration and an explanation of available options:
enabled: true header: true header_interpolated: true body: true body_interpolated: true
enabledlets you turn the plugin off entirely.
bodyfields tell the plugin which parts of the page users are allowed to view. If these are set to false, then the plugin returns a
403 FORBIDDENwhen the source is requested.
body_interpolatedlet the user view the header and body after being processed by the various plugins. If
bodyare set to false, then the accompanying
*_interpolatedis automatically set to false as well.
You can enable/disable permissions on a page-by-page basis by inserting something like the following in the front matter of the page in question:
view-source: header: false body: false
This would fully disable viewing the source of that specific page. You can do this by taxonomy also by using the Header by Taxonomy plugin.
Once enabled, each page view is examined for a query string that contains the parameter
view-source. If found and set to
http://example.com/blog/post?view-source=interpolated), then the mode is set to
interpolated. Any other setting (including blank) will result in the mode being set to
The plugin will then return a
200 OK response with a
Content Type header of
text/plain and the body containing the source code as described below.
The returned header will be the front matter as it appears in the original Markdown file.
The body will be the Markdown itself as it appears in the original Markdown file.
The returned header will be a YAML dump of the page's header (which can be modified in various ways by plugins).
The returned body will usually be the Markdown after any other Markdown-editing plugins are run. You should get the Markdown—not rendered HTML. But this will depend on how the plugins accomplished their task. This plugin grabs the content after the
onPageContentRaw event. See the Grav lifecycle for more details, and let me know if it doesn't work as expected in certain cases.