HTML (Qiq)

Setup

Install bear/qiq-module in composer to get HTML view in Qiq.

composer require bear/qiq-module

Next, Provide a directory to store templates and helpers.

cd /path/to/project
cp -r vendor/bear/qiq-module/var/qiq var

Provide the html context file src/Module/HtmlModule.php and install QiqModule.

namespace MyVendor\MyPackage\Module;

use BEAR\Package\AbstractAppModule;
use BEAR\QiqModule\QiqModule;


class HtmlModule extends AbstractAppModule
{
    protected function configure()
    {
        $this->install(new QiqModule($this->appMeta->appDir . '/var/qiq/template'));
    }
}```

## Change context

Change the context of `bin/page.php` to enable `html`.

```bash
$context = 'cli-html-app';

Template

Prepare the template for the Index resource in var/qiq/template/Page/Index.php.

<h1>{{h $this->greeting }}</h1>

The $body of the ResourceObject will be assigned to the template as $this.

php bin/page.php get /
200 OK
content-type: text/html; charset=utf-8

<h1>Hello BEAR.Sunday</h1>

Custom helper

Custom Helpers will be created in the Qiq\Helper\ namespace. Example: Qiq\Helper\Foo.

Specify the Qiq\Helper in the autoload of composer.json (e.g: composer.json) and run composr dump-autoload to enable to autoload the custom helper class. Custom helpers placed in the specified directory will be made available.

ProdModule

Install a module in ProdModule to render the error page as HTML in production and to compile the templates at build time.

class ProdModule extends AbstractModule
{
    protected function configure()
    {
        $this->install(new QiqErrorModule);
        $this->install(new QiqProdModule);
    }
}

The compile writes the templates into var/build/{context}/qiq, and production serves them from there, read-only. Booting before compiling stops with TemplateNotCompiledException.

The previous form, new QiqProdModule($cachePath), keeps working and compiles at serve time into the path — deprecated.

The argument-less form requires BEAR.QiqModule 2.1+ and BEAR.Package 1.24+.