Skip to content

How to: Adding a custom page

aniela edited this page Oct 7, 2012 · 5 revisions

This article explains how you can create a custom LiteCommerce page from your module.

Creating a new storefront page

1) First of all create a "controller" class for the new page.

The system determines which controller class to use from the "target" parameter. In most cases it is supplied in the page URL. Let's say we want to create a new page and associate it with target = "test".

Create "classes/XLite/Module/[your-dev-id]/[your-module-id]/Controller/Customer/Test.php" file and edit it as follows:

<?php

namespace XLite\Module\[your-dev-id]\[your-module-id]\Cоntroller\Customer;

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

It is empty because you don't need any actions associated with the controller.

2) Now create a widget class that will display the page.

Create "classes/XLite/Module/[your-dev-id]/[your-module-id]/View/TestPage.php" file and edit it as follows:

<?php

namespace XLite\Module\[your-dev-id]\[your-module-id]\View;

/**
 * @ListChild (list="center", zone="customer")
 */
class TestPage extends \XLite\View\AView
    {
    public static function getAllowedTargets()
    {
        $list = parent::getAllowedTargets();

        $list[] = 'test';

        return $list;
    }

    protected function getDefaultTemplate()
    {
        return 'modules/[your-dev-id]/[your-module-id]/test_page/body.tpl';
    }
}

3) Create the page template.

Create "skins/default/en/modules/[your-dev-id]/[your-module-id]/test_page/body.tpl" file and edit it as you need.

4) To apply the changes install the new module (or rebuild the classes cache if it is already installed).

Creating a new back-end page

1) First of all we create a "controller" class for the new page.

The system determines which controller class to use from the "target" parameter. In most cases it is supplied in the page URL. Let's say we want to create a new page and associate it with target = "test".

Create "classes/XLite/Module/[your-dev-id]/[your-module-id]/Controller/Admin/Test.php" file and edit it as follows:

<?php

namespace XLite\Module\[your-dev-id]\[your-module-id]\Cоntroller\Admin;

class Test extends \XLite\Controller\Admin\AAdmin
{
}

It is empty because you don't need any actions associated with the controller.

2) Now create a widget class that will display the page.

Create "classes/XLite/Module/[your-dev-id]/[your-module-id]/View/TestPage.php" file and edit it as follows:

<?php

namespace XLite\Module\[your-dev-id]\[your-module-id]\View;

/**
 * @ListChild (list="admin.center", zone="admin")
 */
class TestPage extends \XLite\View\AView
{
    public static function getAllowedTargets()
    {
        $list = parent::getAllowedTargets();

        $list[] = 'test';

        return $list;
    }

    protected function getDefaultTemplate()
    {
        return ‘modules/[your-dev-id]/[your-module-id]/test_page/body.tpl’;
    }
}

3) Create the page template.

Create "skins/admin/en/modules/[your-dev-id]/[your-module-id]/test_page/body.tpl" file and edit it as you need.

4) You can add the page to the backend menu (optional).

Create "skins/admin/en/modules/[your-dev-id]/[your-module-id]/test_page/link.tpl" file and edit it as follows:

{**
 * @ListChild (list="menu.settings", weight="900")
 *}

<widget class="\XLite\View\TopMenu\Node" title="Example module settings" linkTarget="test" />

Replace "menu.settings" with the actual "view list" in which you want the link to be displayed in.

5) To apply the changes install the new module (or rebuild the classes cache if it is already installed).

Clone this wiki locally