Skip to content
Alex Trofimov edited this page Jul 22, 2014 · 1 revision

Almost every visible page in user side consists of blocks which can be arranged in Studio. Every block on the page is of particular type, for now the following page block types are available:

  • raw: HTML block
  • html: HTML block
  • lang: translatable language string
  • image: just an image
  • rss: RSS block
  • menu: menu block
  • service: service block

All types of blocks are pretty easy to add via Studio page builder, except service block, which require some functionality from backend, this is actually service call to a module to get some content.

We have the following service method available in our module:

function serviceTest () 
{
    return str_repeat(_t('_vnd_test_phrase'), getParam('vnd_test_repeat_times'));
}

It just displays language string the number of times specified in module settings, by default 3 times. We will use it to add service block to newly created page.

To help you create pages (and other DB things) for modules there is Developer module. Go to:
Studio > Developer > select Page Builder in left vertical menu > click 'Add New Page'
In opened popup enter the following values:

Dolphin U page add

Name: vnd_test_main - internal page name
Module: Test - module, the page belongs to
System Title: _vnd_test_page_sys_main - page title to display in Studio
Title: _vnd_test_page_main - page title to display to user
URI: test-main - page URI, must be uniq
URL: page.php?i=test-main - full page URL, using above URI
Layout: 1-column - layout to use for the page
Deletable: no - allow to delete this page
Class Name: [leave empty] - class name for custom page behaviour
Class File: [leave empty] - class file with path for above class

Translation for above language keys must be added as well, to the lang file in the module folder: install/langs/en.xml. Let's call it Test for both language keys.

Then we will add service block for our serviceTest method in our module:
Click 'Add blocks' > Skeletons > select 'Service' block > click 'Add to Page'

Dolphin U add page block

And edit just added block by clicking on it and enter the following values in the popup:

Dolphin U edit page block

Name: vnd_test_main - page name the block belongs to (it should be set automatically)
Module: Test - module the block belongs to (it should be set automatically)
Title: _vnd_test_page_block_phrase - block title to display to user
Layout: Content + title + background + padding - block layout, they may look different for different templates
Visible For: Anyone - membership level to show this block to
Code: array ('module' => 'vnd_test', 'method' => 'test') - this is actually service call to our service method serviceTest
Deletable: no - allow to delete this block
Copyable: yes - allow to copy this block to other pages
Active: yes - activate block by default

Translation for _vnd_test_page_block_phrase language key should be added the similar way as for the page, we will use 'Test phrase' for it.

Now we can test the result by clicking on 'View Page' button, something like this should be shown:

Dolphin U ready page preview

Everything works, except one thing - language keys aren't translated, so they are in language file, but not loaded into the system, here is the situation where Developer module can help, go to:
Studio > Developer > Polyglot > click 'Restore' button for 'Test' module
After languages are recompiled, reload the page we just created, it should look like this:

Dolphin U final page view

Now the page works, but it will disappear when we uninstall the module, so we need to add it to installation file. Developer module can help with it as well - select newly created page in Developer Page Builder and click 'Export Page' button:

Dolphin U export page to SQL query

Get code from 'Adding to database' area and insert it to the end of install/sql/enable.sql file, code from 'Removing from database' goes into install/sql/disable.sql file.

However one more additional manual SQL query may be required to insert into install/sql/disable.sql file for situations when page block was copied to other pages, they can be identified by module name:

DELETE FROM `sys_pages_blocks` WHERE `module` = 'vnd_test';

After installation files are updated you can safely enable/disable or even install/uninstall module without loosing just created page.

Clone this wiki locally