This page will contain several components of the KikCMS you should familiarize yourself with to properly use the KikCMS and also to learn about it's capabilities.
Before you begin, make sure that you have setup a working dev environment.
Templates are what determine how a page looks. Each page you create in the CMS has it's own template. We will show you here how to create one.
1. Edit the following file, which looks something like this:
<?php
class TemplateFields extends TemplateFieldsBase
{
public function getTemplates(): array
{
return [
(new Template('home', 'Homepage')),
(new Template('default', 'Default', ['content'])),
];
}
public function getFields(): array
{
return [
'content' => (new WysiwygField('content:value', 'Page content', [new PresenceOf])),
];
}
}
2. Add this to the getTemplates
array:
(new Template('mytemplate', 'My template', ['content']))
Now when you create or edit a page, you have the option to choose the 'My template' template. The 3rd parameter contains which fields are in this template. You don't have to concern about that for now, just know that your template has a rich text editor for the field 'content'.
Create the following file with the following content:
{% extends '@website/base.twig' %}
{% block templateBody %}
<div style="background-color: #eee">
My custom template content:
<br><br>
{{ content|raw }}
</div>
{% endblock %}
DataTable's are great to edit data, and here we'll show you how to use the data in your website. Note that this could be done with any data, not just data that was added using a DataTable.
Before proceeding, make sure you have a DataTable ready in the backend and added some records.
Now add this piece of code:
public function getHomeVariables(): array
{
return [
'persons' => Person::find(),
];
}
This tells the CMS to add an array of persons to the home template. The find mathod is part of Phalcon. You can now use this in the home template:
{% for person in persons %}
<div>{{ person.name }}</div>
{% endfor %}
If you followed the previous part, you now output the person's name. Now change the code a little to add an image:
{% for person in persons %}
<div>
{{ person.name }}<br>
<img src="{{ mediaFile(person.image_id, 'default') }}">
</div>
{% endfor %}