Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

pistom/crayon-cms

Repository files navigation

Crayon CMS

A simple CMS, which requires no database. All data are stored in twig and json files.

Demo: cms.cinquiemecrayon.eu

Installation

  1. Clone or download the CMS source.
  2. Run composer to download dependencies.
  3. Change file name _install.dist to _install.php
  4. Run yarn.
  5. Generate assets:
    • Develop npm run dev
    • Production npm run prod
  6. Go to Back Office (yourdomain/_bo) and change admin password.
  7. Configure site (yourdomain/_bo/settings.php).

Routing

Crayon CMS uses the altorouter routing class.

Path

Blog

| function     | variable       | example                |
|--------------|----------------|------------------------|
| articlesList | [i:page]?      | blog/[i:page]?/        |
| article      | [slug:article] | blog/[slug:article]    |

Variables of the path are passed to the controller in the $dp array.

Variables

Variables are divided by | character. They are passed to the controller in the $sp array.

SiteController

| function | 1st variable  | 2nd variable |
|----------|---------------|--------------|
| page     | alias of page | -            |
| contact  | menu name     | -            |

BlogController

| function     | 1st variable                 | 2nd variable |
|--------------|------------------------------|--------------|
| articlesList | id of category (0 for all    | menu name    |
|              | categories assigned to menu) |              |
| article      | -                            | -            |

Twig

Global variables

root

Site main directory.

routes

Array with created routes.

Examples:

Generate link:

<a href="{{ root~routes['home'].path }}">{{ routes['home'].name }}</a>

settings

Array with site settings.

Examples:

<title>{{ settings['site_name'] }}</title>

Templates

You can create your own twig templates by overloading the base template. Place your files in /views/_templates/{name of template} directory. The directory structure should be the same as the main view directory. Example:

/views/_templates/new_template/base.html.twig
/views/_templates/new_template/blog/article.html.twig

The folder name with the new template appears in the settings.

Translations

You can use the twig global variable t for rendering strings.

Example:

<p>{{ t.message }}</p>

Add this line:

<scipt src="{{ root }}/js/translation.js?lang={{ menu.lang }}"></script>

to your template for generate an js global object with current language's translations. You can use this object in your js. Exaple:

alert(translate.thank_you);

Users

You can create new users in admin panel. To give the user permission to edit content in the admin panel you need to add the appropriate permissions in data/users.json file. Example:

{
  "123": {
    "role": "",
    "pwd": "password",
    "permissions": [
      "pages",
      "files",
      "files.manager",
      "files.uploader",
      "file.upload",
      "file.remove",
      "gallery",
      "gallery.items"
    ]
  }
 }

Permission names are filenames in the _bo directory.