Skip to main content
page last edited on 10 October 2022

Basic Page (hello world)

Version: 5.5.0

To create a basic page, first, create a controller (route), complement it with a widget, and, finally, bind them together.

Controller(XCart)

A controller must be declared within a specific zone (admin or customer). To add a controller for a customer zone, create a class in <XCart>/modules/{AdminId}/{ModuleId}/src/Controller/Customer .

Use the class name as a routing target parameter converting the UpperCamelCase (PascalCase) into snake_case.

For example:

Class: \XCExample\SampleModule\Controller\Customer\SamplePage

URI: /?target=sample_page

Depending on the zone, a class must extend either \XLite\Controller\Customer\ACustomer or \XLite\Controller\Admin\AAdmin.

<?php

namespace XCExample\SampleModule\Controller\Customer;

class SamplePage extends \XLite\Controller\Customer\ACustomer
{
}

After creating a controller, execute the following command:

# ./bin/service xcst:rebuild

Widget

A widget must be added to a corresponding list. For a sample page in the customer area, the list name is center.

It is also necessary to declare the allowed target and template.

<?php

namespace XCExample\SampleModule\View;

use XCart\Extender\Mapping\ListChild;

/**
* @ListChild (list="center")
*/
class SamplePage extends \XLite\View\AView
{
/**
* @return array
*/
public static function getAllowedTargets()
{
return array_merge(parent::getAllowedTargets(), ['sample_page']);
}

/**
* @return string
*/
protected function getDefaultTemplate()
{
return 'modules/XCExample/SampleModule/sample_page/body.twig';
}
}

Execute the following command after adjusting the View lists. # ./bin/console xcart:service:refresh-view-lists

Template

Module templates are stored in the <XCart>/modules/{AuthorId}/{ModuleId}/templates/{interface}/{zone} folder.

It is also necessary to add the modules/{AuthorId}/{ModuleId}/ path for the module's templates. This is required to get an opportunity to redefine the core and other modules’ templates in skins.

For a template to be accessible for a widget (and for rendering) in the web interface and customer area, create a twig template with the path: <XCart>/modules/XCExample/SampleModule/templates/web/customer/modules/XCExample/SampleModule/sample_page/body.twig

{#
# Template for sample page
#}
Sample page content

Results

As a result, when opening <shop-url>/?target=sample_page in the customer area, the page will display the following text:

Sample page content