Creating Content

Phile is a flat file CMS, this means there is no administration backend and database to deal with. You simply create .md files in the "content" folder and that becomes a page. For example, this file is called index.md and is shown as the main landing page.

If you create a folder within the content folder (e.g. content/sub) and put an index.md inside it, you can access that folder at the URL http://yousite.com/sub. If you want another page within the sub folder, simply create a text file with the corresponding name (e.g. content/sub/page.md) and you will be able to access it from the URL http://yousite.com/sub/page. Below we've shown some examples of content locations and their corresponding URL's:

Physical Location URL
content/index.md /
content/sub.md /sub
content/sub/index.md /sub (same as above)
content/sub/page.md /sub/page
content/a/very/long/url.md /a/very/long/url

If a file cannot be found, the file content/404.md will be shown.

Text File Markup

Text files are marked up using Markdown. They can also contain regular HTML.

At the top of text files you can place a block comment and specify certain attributes of the page. For example:

/*
  Title: Welcome
  Description: This description will go in the meta description tag
  Author: Joe Bloggs
  Date: 2013/01/01
  Robots: noindex,nofollow
  */

Phile also allows HTML style block comments:

<!--
  Title: Welcome
  Description: This description will go in the meta description tag
  Author: Joe Bloggs
  Date: 2013/01/01
  Robots: noindex,nofollow
  -->

Custom Meta

You can actually create custom meta attributes by default in Phile. If you want to add a date, author, or even something else, this can be done easily. These values will be contained in the {{ meta }} variable in themes (see below).

Custom Meta Ordering

You can order pages by their custom meta attributes. Like creating an Order meta for each page, then you can use $config['pages_order_by'] = "meta:order"; in your config.php file.

Themes

You can create themes for your Phile installation in the "themes" folder. Check out the default theme for an example of a theme. Phile uses Twig for it's templating engine. You can select your theme by setting the $config['theme'] variable in config.php to your theme folder.

All themes must include an index.html file to define the HTML structure of the theme. Below are the Twig variables that are available to use in your theme:

  • {{ config }} - Contains the values you set in config.php (e.g. {{ config.theme }} = "default")
  • {{ base_dir }} - The path to your Phile root directory
  • {{ base_url }} - The URL to your Phile site
  • {{ theme_dir }} - The path to the Phile active theme directory
  • {{ theme_url }} - The URL to the Phile active theme directory
  • {{ content_dir }} - The path to the content direcotry
  • {{ content_url }} - The URL to the content directory
  • {{ site_title }} - Shortcut to the site title (defined in config.php)
  • {{ meta }} - Contains the meta values from the current page
    • {{ meta.title }}
    • {{ meta.description }}
  • {{ content }} - The content of the current page (after it has been processed through Markdown)
  • {{ pages }} - A collection of all the content in your site
    • {{ page.title }}
    • {{ page.url }}
    • {{ page.content }}
  • {{ current_page }} - A page object of the current_page

Page listing example:

<ul class="nav">
  {% for page in pages %}
  <li><a href="{{ page.url }}">{{ page.title }}</a></li>
  {% endfor %}
  </ul>

Config

You can override the default Phile settings (and add your own custom settings) by editing config.php in the root Phile directory. The config.php file lists all of the settings and their defaults. To override a setting, simply uncomment it in config.php and set your custom value.

Events

In the core we trigger a lot of events, which help to manipulate content or other stuff within a plugin. To use the event system, you only have to register your plugin for a specific event, look at the example plugin for more an example.

The following list shows all events.

plugins_loaded

this event is triggered after the plugins loaded

param type description
plugins array Plugin classes of all loaded plugins

config_loaded

this event is triggered after the configuration is fully loaded

param type description
config array the complete configuration

after_init_core

this event is triggered after the core is initialized

param type description
response \Phile\Core\Response the response

request_uri

this event is triggered after the request uri is detected.

param type description
uri string the requested uri (without install_path)

after_404

this event is triggered after a requested page is not found

after_resolve_page

this event is triggered after a request is resolved to a page

param type description
pageId string the requested page-ID
page Phile\Model\Page the page served

before_init_template

this event is triggered before the the template engine is init

before_render_template

this event is triggered before the template is rendered

param type description
templateEngine \Phile\Template\TemplateInterface the template engine

template_engine_registered

this event is triggered before the template is rendered

param type description
engine \Phile\Template\TemplateInterface the raw template engine
data array the variables being sent to the template engine

after_render_template

this event is triggered after the template is rendered

param type description
templateEngine \Phile\Template\TemplateInterface the template engine
output string the parsed and ready output

before_read_file_meta

this event is triggered before the meta data is read and parsed

param type description
rawData string the unparsed data
meta \Phile\Model\Meta the meta model

after_read_file_meta

this event is triggered after the meta data is read and parsed

param type description
rawData string the unparsed data
meta \Phile\Model\Meta the meta model

before_load_content

this event is triggered before the content is loaded

param type description
filePath string the path to the file
page \Phile\Model\Page the page model

after_load_content

this event is triggered after the content is loaded

param type description
filePath string the path to the file
rawData string the raw data
page \Phile\Model\Page the page model

before_parse_content

this event is triggered before the content is parsed

param type description
content string the raw data
page \Phile\Model\Page the page model

after_parse_content

this event is triggered after the content is parsed

param type description
content string the raw data
page \Phile\Model\Page the page model

Service Locator

Within in the core we use a lot of service class, which will be received over the ServiceLocator class. This makes it possible to replace a service with a complete new logic. In the following section, we tell you, which service classes available and how to replace a service with your own.

Service: Phile_Parser

You can replace the markdown parser with your own parser, if you like. This works by overloading the default parser with a plugin. To show you, check out the Markdown plugin that comes with Phile. Or, take a look at the Sundown-Parser-Plugin.

To replace the parser, you need only one line of code to register a new parser:

\Phile\ServiceLocator::registerService('Phile_Parser', new \Phile\Parser\Sundown($this->settings));

Service: Phile_Parser_Meta

You can override the meta data parser with your own. The default parser handles meta in either a HTML block comment or a Javascript/PHP block comment. If you wanted to support YAML, this would be the service you would override.

Service: Phile_Template

The template engine is also a service, you can replace the default template engine (twig) with your own. The way you can do this, is the same like the Phile_Parser:

\Phile\ServiceLocator::registerService('Phile_Template', new \Phile\Template\MyTemplateEngine());

Service: Phile_Cache

Internal PhileCMS use an object cache to improve the performance. however if you want another cache system, register your own:

\Phile\ServiceLocator::registerService('Phile_Cache', new \Phile\Cache\MyCacheEngine());

Service: Phile_Data_Persistence

Yes, Phile works without any database, but if you need the possiblity to persist data, you can use the Phile_Data_Persistence service. with the core we provide you a simple file based data storage, you can implement your own or maybe found a plugin with another storage engine, replace it like this:

\Phile\ServiceLocator::registerService('Phile_Data_Persistence', new \Phile\Persistence\MyPersistenceEngine());