How To Blog


The following instructions are assuming you are using the default Phile installation (Twig Templates and the Markdown parser).


Please see the blog demo theme.

Organizing Content

IMPORTANT: Here is the typical way that content files work in Phile:

Path URL
content/ /
content/ /sub
content/sub/ /sub (same as above)
content/sub/ /sub/page
content/a/very/long/ /a/very/long/url

Here are some typical blogging style URL structures. You can re-create URL styles with folder structure:

Path URL
content/posts/ /posts/article
content/2013/11/10/ /2013/11/10/post-name
content/category/dogs/ /category/dogs/about-huskies
content/tags/cats/ /tags/cats/about-long-hairs

Using Images

Images just need the path to where they exists. So this path:



{{ base_url }}/content/images/picture.jpg

Or if there was an image in the theme:

{{ theme_url }}/images/theme-logo.png

Splitting Content

There are a couple ways to split content. The reasons you might want to do that is for things like sidebars, widgets, accordions, tabbed panes, column content, etc.

Here is a demo of how to split content without plugins:

### Section 1

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.


### Section 2

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Now in your HTML you can split at that <hr> tag:

<div class="column-1">
  {{ content|split('<hr>')[0] }}
<div class="column-2">
  {{ content|split('<hr>')[1] }}

The <hr> tag is not the special thing here. The split filter in Twig is the special function. You can use any tag or made-up tag (how about <split>?) to do this.

This can even be done across different partials or be conditial based on some meta tag.

JavaScript Constants

Here is a trick to get access to Phile variables in your javascript.

  <!-- a bunch of stuff here -->
  <script type="text/javascript">
  // bind a phile object to the window
  window.Phile = {
    const: {
      root_dir: '{{ constant('ROOT_DIR') }}',
      content_dir: '{{ constant('CONTENT_DIR') }}',
      content_ext: '{{ constant('CONTENT_EXT') }}',
      lib_dir: '{{ constant('LIB_DIR') }}',
      plugins_dir: '{{ constant('PLUGINS_DIR') }}',
      themes_dir: '{{ constant('THEMES_DIR') }}',
      cache_dir: '{{ constant('CACHE_DIR') }}'
    base_url: '{{ base_url }}',
    theme_url: '{{ theme_url }}',
    config: JSON.parse('{{ config|json_encode() }}') // encode the config array to a string and then parse that string

Now you can access window.Phile and see some of the settings and constants.

Ajax Demo

Here is a simple demo of using the above settings to make an ajax call (using jQuery) to some other content:

$.get(Phile.base_url + '/sub/page', function(data) {
  // print out the HTML for parsed sub/page file

Edit the source page on github…