I've been using PHP to develop websites since the mid 90's and, even though I'm really happy with my Raspberry Pi and Pelican setup, I really wanted to add some php code into some of my scripts. After spending a while testing a few approaches out, I finally found one that worked and seamlessly integrated into the Pelican framework.

You'll need to have PHP running on your webserver for this to work. Also, I use the bootstrap3 templates on my site but the process outlined below should work for all Pelican templates.

Create your template files.

Firstly, in your templates directory, make a copy of the article.html template file. Call this new template phpfile.html

Change the first line:

{% extends "base.html" %}


{% extends "phpbase.html" %}

Next, copy base.html to phpbase.html and edit the layout as you wish (or leave it as it is if you don't need to change it.)

Create your markdown file.

Create the markdown file as follows:

Date: 2014-03-20
Title: PHP Test
url: php-test.php
save_as: php-test.php
Template: phpfile
Tags: test
Slug: php-test
Category: Testing
Summary: Test for PHP code

That's all there is to it. (I'm assuming you can do this with other files except for markdown.) The page is generated as per usual and the php page is created rather than a regular html page.

Date Category Technology  Tags pelican / php
Gary Hall
Article by Gary Hall
A teacher based in Beverley, England. Enjoys walking, travelling, reading and writing interesting content to help others. Feel free to comment below.


comments powered by Disqus