Creating pages for the Memphis view engine

Pages are configured in the path/to/stubbles/pages directory. The place of this directory can be configured in config/php/config.php within the getPagePath() method. The name of the files must be pagename.xml where pagename will be the value for the page request param to access this page. The contents of such a page configuration may look like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<xj:configuration
    xmlns:xj="http://xjconf.net/XJConf"
    xmlns="http://stubbles.net/websites">
  <page>
    <properties>
      <property name="title">Top-Themen</property>
    </properties>
    <includeFile source="static/static.html" parts="content" name="static"/>
    <includeTemplate source="foo.tmpl" parts="header,content" name="foo"/>
    <loadExtension extension="org::stubbles::examples::memphis::ExampleMemphisExtension" parts="content" name="faq"/>
  </page>
</xj:configuration>

Page properties

The page properties are a list of key-value pairs to give a more specific configuration for the page. Currently three different properties are supported:

  • title: This will be used to set the content of the {PAGE_TITLE} place holder in the frame.
  • frame: This defines the frame to be used when this page is accessed. It needs to be one of the names defined in the configuration of the Memphis view engine.
  • frame_fixed: if this property exists it is not possible to change the frame of the page via the request param frame or from within the session. The value of this property is ignored.
  • forceSSL: This property will force a redirect to the same page, but with https instead of http if the current request was not in SSL mode.

All page properties are optional.

Page elements

Stubbles delivers three different page elements to be used in the Memphis view engine:

  • The includeFile page element takes a source file as argument and returns the contents of this files. The source file needs to reside in the template directory.
  • The includeTemplate page element takes a template file as argument, applies patTemplate onto the given template file and returns the contents of the parsed template. The source template needs to reside in the template directory.
  • The loadExtension page element takes the full qualified name of a class implementing the net::stubbles::websites::memphis::stubMemphisExtension interface, executes this class and returns the return value of this execution.

For every page element its name must be defined. The name determines which request params can be accessed by the page element. In this example, the loadExtension page element with name faq can only access request params prefixed with faq_.

Additionally the parts in which the page element is included can be configured. If the parts attribute is missing the content of the page element will be displayed in all defined parts. To restrict this the list of parts where the content should be displayed can be set with this attribute. In the example above the first and the last page elements are only displayed in the part content, while the second page element will be displayed in the parts header and content.

Extensions

With the loadExtension page element it is possible to execute own source code. To create such an extension one must implement the net::stubbles::websites::memphis::stubMemphisExtension interface. Probably it is a bit easier to extend the net::stubbles::websites::memphis::stubMemphisAbstractExtension class which means that only the process() method needs to be implemented. This method must return the content to be displayed in the given part.

Within the extension one has access to the request, session and response instances. Additionally the associative array $context contains useful informations:

  • part: the name of the part which is currently processed.
  • page: the page instance for the requested page.
  • template: instance of net::stubbles::websites::memphis::stubMemphisTemplate. Notice: This one is only available when process() is executed, but not when isCachable(), getCacheVars() or getUsedFiles() are executed.

Please bear in mind that each of the methods is executed for every part for which the page element is available.