Setting up a project and the webspace

Development
Applies to: every Sulu website As of Sulu 3.0

In short

You create the skeleton with composer create-project sulu/skeleton and build the database with sulu:build. Sulu looks for templates in config/templates/{pages,articles,snippets,blocks}. The webspace file in config/webspaces/ defines languages, default templates, menus and addresses per environment.

A Sulu 3 project starts from the skeleton of the Sulu developers. This chapter covers the steps up to the first login and what the webspace file defines. The example is the file of the website bertrams-media, with the domains replaced by example.

Helpful first: 5.1 Sulu 3 at a glance

Installing

The guide “Getting Started” in the official documentation names three commands. They create the project, build the database and start a PHP server. Before that, enter the connection to the database as DATABASE_URL in the file .env.local. MySQL, MariaDB and PostgreSQL are supported, SQLite is not.

Installation following the official guide bash
composer create-project sulu/skeleton my-project -n

# set DATABASE_URL in .env.local, then:
php bin/adminconsole sulu:build dev
php -S localhost:8000 -t public/ config/router.php

Where Sulu looks for templates

Sulu reads XML templates from fixed directories in the project:

  • config/templates/pages for pages
  • config/templates/articles for articles
  • config/templates/snippets for snippets
  • config/templates/blocks for global blocks

The matching Twig files live under templates/; the path is given in the template in the element <view>. You add further directories under sulu_admin.templates.<type>.directories. The example website does this in config/packages/sulu_admin.yaml for the testimonials. How the templates are built is covered in the chapters “Page templates: XML and Twig” and “Blocks, global blocks, includes and atoms”.

The webspace file

A webspace is a website in the project. Its file lives in config/webspaces/. The example website has two: bertrams-media.de.xml for the main website and infinity.xml for a stage page. This is the main file, shortened:

config/webspaces/example.xml, shortened from the file of the example website html
<?xml version="1.0" encoding="utf-8"?>
<webspace xmlns="http://schemas.sulu.io/webspace/webspace"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://schemas.sulu.io/webspace/webspace http://schemas.sulu.io/webspace/webspace-1.1.xsd">
    <name>example</name>
    <key>example</key>

    <localizations>
        <localization language="de" default="true"/>
        <localization language="en"/>
    </localizations>

    <default-templates>
        <default-template type="home">default</default-template>
        <default-template type="page">default</default-template>
    </default-templates>

    <templates>
        <template type="search">pages/search</template>
        <template type="error">error/error</template>
        <template type="error-404">error/error</template>
    </templates>

    <navigation>
        <contexts>
            <context key="main">
                <meta>
                    <title lang="en">Main Navigation</title>
                    <title lang="de">Hauptnavigation</title>
                </meta>
            </context>
        </contexts>
    </navigation>

    <portals>
        <portal>
            <name>example</name>
            <key>example</key>
            <environments>
                <environment type="prod">
                    <urls>
                        <url language="de">www.example.de</url>
                        <url language="en">www.example.com</url>
                    </urls>
                </environment>
                <environment type="dev">
                    <urls>
                        <url language="de">local.example.de</url>
                        <url language="en">local.example.com</url>
                    </urls>
                </environment>
            </environments>
        </portal>
    </portals>
</webspace>
  • key must be unique among all webspaces. Routes and snippet areas depend on it, so do not change it later.
  • localizations names the languages, one of which is default. The example website has de, en and nl.
  • default-templates defines which template a new home page (home) and a new page (page) get. The home page of the example website uses onepage.
  • templates assigns special pages: search, error page and the 404 page.
  • navigation/contexts are the menus into which the admin lets you hang pages. The example website has main, footer, footer-bottom and links.
  • environments assign an address to each environment and language. The type (prod, stage, test, dev) is compared with kernel.environment, that is, with APP_ENV.

Several webspaces

The main website and the stage page run in the same project. So that the stage does not offer all page templates, its file excludes onepage and sidebar with <excluded-templates>. The element hides templates in the selection field of the page form.

Articles belong to a main webspace. The example website sets it in config/packages/sulu_article.yaml: sulu_article.default_main_webspace: bertrams-media. Snippets, by contrast, are not tied to a webspace.

Adding another webspace

The cookbook “Adding new Webspace” in the official documentation describes the steps. Afterwards, clear both caches (see “Sulu 3 at a glance”) and check that the domain points to the same public/ in the web server.

More on this

Official documentation