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" %}

to

{% 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
<?phpinfo();?>

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.


Comments

comments powered by Disqus
Gary Hall Gary Hall is based in East Yorkshire, England, and has a background in education, marketing and technology. This site is a collection of ideas and resources on these topics.