Your first site
From an empty install to a section of your own that shows a component of your own through an XSLT view. You need the empty variant of Installation and its administrator. The commands run in the project's folder as the site's user.
While you build, keep 'debug' => 1 in htdocs/system.config.php, and after changing it run php index.php setup linker from htdocs/. On a live site set it back to 0.
1. A section
- Sign in at
/login/and open «Управление структурой» (Structure management),/admin/structure/. - Select «Главная страница» (Home page) in the tree and press «Добавить» (Add), the plus under the tree.
- Fill in the form:
- «Содержимое страницы» (Page content) — «Текстовая страница» (Text page);
- «Макет страницы» (Page layout) — «Базовый» (Basic); both lists open on other items, so choose both;
- «Сегмент URI» (URI segment) —
releases; - on the tabs «Русский» and «Українська», «Название раздела» (Section name) —
Releases: a name is required in each language.
- Press «Сохранить» (Save).
The section opens at /releases/ with its name as the heading, and the main menu shows it: a new section gets the tag menu.
2. A text
On /releases/ turn on «Режим редактирования» (Edit mode) on the page toolbar, click the text block — it shows -- while empty — and write. The text is saved when you leave the page: turn edit mode off. Do it in Firefox: Chromium-based browsers — Chrome, Edge — block that request, and the text is lost.
3. A component
Create site/modules/main/components/ReleaseList.php:
<?php
namespace EnergineSite\main\components;
use Energine\share\components\DataSet;
use Energine\share\gears\DataDescription;
use Energine\share\gears\FieldDescription;
use Energine\share\gears\SimpleBuilder;
class ReleaseList extends DataSet {
public function __construct($name, ?array $params = null) {
parent::__construct($name, $params);
$this->setType(self::COMPONENT_TYPE_LIST);
}
protected function createBuilder() {
return new SimpleBuilder();
}
protected function createDataDescription() {
$result = new DataDescription();
foreach (['version', 'note'] as $fieldName) {
$field = new FieldDescription($fieldName);
$field->setType(FieldDescription::FIELD_TYPE_STRING);
$result->addFieldDescription($field);
}
return $result;
}
protected function loadData() {
return [
['version' => '2.12', 'note' => 'PHP 5.5+'],
['version' => '2.13', 'note' => 'PHP 8.4+, MariaDB 10.11+'],
];
}
}
The starter's Composer autoloader maps EnergineSite\ to site/modules/, so the class needs no registration. DataSet builds the component's XML: createDataDescription() names the fields, loadData() returns the rows and SimpleBuilder writes them out. The component is not active, so it needs no config.
4. A page template
Copy the core's text page into your site:
cp core/modules/share/templates/content/textblock.content.xml site/modules/main/templates/content/releases.content.xml
In releases.content.xml, add your component after the textBlock_1 component:
<component name="releaseList" class="EnergineSite\main\components\ReleaseList"/>
A new template needs its link in htdocs/:
cd htdocs
php index.php setup linker
In «Управление структурой» select «Releases», press «Редактировать» (Edit), the pencil, choose CONTENT_RELEASES in «Содержимое страницы» and save. A template shows its constant until the constant has a translation: add CONTENT_RELEASES in «Редактор переводов» (Translations editor) to give it a name. The text of step 2 stays: it is text block 1 of this page.
5. An XSLT view
Create site/modules/main/transformers/releases.xslt:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="component[@class='ReleaseList']" priority="1">
<ul class="release_list">
<xsl:for-each select="recordset/record">
<li>
<strong><xsl:value-of select="field[@name='version']"/></strong>
<xsl:text>: </xsl:text>
<xsl:value-of select="field[@name='note']"/>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
and include it in site/modules/main/transformers/include.xslt, after energine.xslt:
<xsl:include href="releases.xslt"/>
priority="1" puts your template above the generic view of lists. Stylesheets are read where they lie, so no setup run is needed: reload /releases/, and under the text the list shows «2.12: PHP 5.5+» and «2.13: PHP 8.4+, MariaDB 10.11+».
6. The page's XML
With debug mode on, /releases/?debug returns the page's XML. Your component is there as <component name="releaseList" componentAction="main" class="ReleaseList" … type="list"> with a <recordset> of <record> elements and <field name="version"> in each: that is what your template matches. See Components and XSLT views.
What needs a setup run
| Change | Run |
|---|---|
a PHP class in site/modules/main/components/ |
nothing |
a new file in site/modules/main/templates/ |
php index.php setup linker |
| an edit of a template, a config or a stylesheet | nothing |
| a new image, script or style | php index.php setup linker, and php index.php setup scriptMap for a script |
the value of debug |
php index.php setup linker |