Creating Views

All views have both, a .html and .php file located within the /views/html and /views/php directories respectively. Due to auto-routing being enabled by default, it's generally best practice to name the views corresponding to the path within the web browser. For example, the URL https://domain.com/services/hosting would display the view located at /views/html/services/hosting.html.

NOTE: Using auto-routing is not required, and if preferred, you may define each individual route. See the HTTP Router section for details.

Create New View

If you do not already have a package created to develop with, create one with the terminal command:

apex package create demo

You should always create new views via the CLI command as it will register the view to your package ensuring it gets included upon publishing to the repository. You may create a new view with the create view command, such as:

apex create view demo services/hosting

This will register the view to the demo package, and create two new files at:

  • /views/html/services/hosting.html
  • /views/php/services/hosting.php

Add any desired contents to the hosting.html file, then open your browser to http://localhost/services/hosting to see the page. With auto-routing enabled by default, the path viewed within your browser will be mapped to the appropriate file located relative to the /views/html/ directory.

Page Titles

Within each view, you should always place the page title at the very top surrounded by <h1> .. </h1> tags. Upon rendering the view, it will be automatically extracted and used as a replacement to the <s:page_title> tag, allowing designers to place page titles within complex HTML structures.

For example:

<h1>Hosting Services</h1>

<p>Below details our hosting services that are on offer.</p>

When the view is rendered, <h1>Hosting Services</h1> will be extracted out of the view, and used in place of all occurrences of the <s:page_title> tag. This allows designers to place page titles within complex HTML snippets, while keeping things simplistic for back-end developers.