Using PHP in Jeykll
I use Jekyll for a blog at work and love the simplicity it provides in creating static html files. But I recently needed to have a block of PHP code executed at run time (when a user requests the page). Since we host our Jeykll blog on a LAMP stack I justed added a .htaccess
file with:
AddType application/x-httpd-php .html .htm
Then put all the PHP that is needed in the html templates. It's a little dirty but works a treat!
Example:
In my _layouts/default.html
:
<?php if(!isset($_GET['ajax'])): ?>
<!DOCTYPE html>
<html>
<head>
<title>{{ page.title }}</title>
...
</head>
<body>
<?php endif; ?>
{{ content }}
<?php if(!isset($_GET['ajax'])): ?>
</body>
</html>
<?php endif; ?>
Simples!
Written by Chris Hale
Related protips
1 Response
Note: this obviously won't work on Github pages.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#