Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

By hand: a module with a view

The page /hello/world/<name>: module.php with a policy, a view that validates its parameter and uses the fetch function, a template in the standard design, all verified.

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/extension-development/part-3-extension-developer/tutorials/by-hand-module-with-a-view.md

On this page

By hand: a module with a view

Tutorial 12. You add a page to mysite_hello: /hello/world/Ada greets Ada and lists the newest articles, using the fetch collection of the previous tutorial. The files passed php -l; with the kernel loaded, the module was found by eZModule::exists( 'hello' ) with its view, and the template rendered as shown.

1. module.php

extension/mysite_hello/modules/hello/module.php (the folder already exists from the fetch function, and ExtensionRepositories[]=mysite_hello registers it):

<?php
$Module = array( 'name' => 'Hello' );

$ViewList = array();
$ViewList['world'] = array(
    'script' => 'world.php',
    'params' => array( 'Name' ),
    'functions' => array( 'read' ),
    'default_navigation_part' => 'ezcontentnavigationpart' );

$FunctionList = array();
$FunctionList['read'] = array();

The view requires the policy hello/read.

2. The view

extension/mysite_hello/modules/hello/world.php:

<?php
/** @var eZModule $Module */
$Module = $Params['Module'];

$name = isset( $Params['Name'] ) && is_string( $Params['Name'] ) && $Params['Name'] !== ''
      ? $Params['Name'] : 'world';

$tpl = eZTemplate::factory();
$tpl->setVariable( 'name', $name );
$tpl->setVariable( 'newest', mysiteHelloFunctionCollection::fetchNewest( 'article', 2, 3 )['result'] );

$Result = array();
$Result['content'] = $tpl->fetch( 'design:hello/world.tpl' );
$Result['path'] = array( array( 'text' => ezpI18n::tr( 'extension/mysite_hello', 'Hello' ), 'url' => false ) );

3. The template

extension/mysite_hello/design/standard/templates/hello/world.tpl:

<section class="mysite-hello">
    <h1>{'Hello, %name!'|i18n( 'extension/mysite_hello',, hash( '%name', $name|wash ) )}</h1>
    {if $newest|count}
    <h2>{'Newest articles'|i18n( 'extension/mysite_hello' )}</h2>
    <ul>
    {foreach $newest as $node}
        <li><a href={$node.url_alias|ezurl}>{$node.name|wash}</a></li>
    {/foreach}
    </ul>
    {/if}
</section>

and register the design in extension/mysite_hello/settings/design.ini.append.php:

<?php /* #?ini charset="utf-8"?

[ExtensionSettings]
DesignExtensions[]=mysite_hello

*/ ?>

Rendered with the name Ada <b>, the heading came out as Hello, Ada &lt;b&gt;!: the name is escaped before it goes into the translated sentence.

4. Switch on, grant, open

php -l extension/mysite_hello/modules/hello/module.php
php -l extension/mysite_hello/modules/hello/world.php
php bin/php/ezcache.php --clear-all

Grant hello/read to the Anonymous role (or another role) in Users > Roles and policies, then open /hello/world/Ada. Without the policy you get the access denied page, which is the point of step 1.

5. If it does not work

SymptomFix
"The requested module does not exist"ExtensionRepositories[], caches
Access deniedgrant hello/read
Layout with an empty content areathe template path, DesignExtensions[], and --clear-id=template-override for a new template

6. Commit

git -C extension/mysite_hello add modules design settings
git -C extension/mysite_hello commit -m "Added: The page hello/world, greeting a visitor and listing the newest articles"

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x