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.
Series 5: Sulu for developers Chapter 2 of 16
Setting up a project and the webspace
In short
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.
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
sulu:build dev creates the user admin with the password admin. On a server, use sulu:build prod and create the first user yourself with sulu:security:user:create. The command expects seven values in this order: username, first name, last name, email, language, role and password.
Where Sulu looks for templates
Sulu reads XML templates from fixed directories in the project:
config/templates/pagesfor pagesconfig/templates/articlesfor articlesconfig/templates/snippetsfor snippetsconfig/templates/blocksfor 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:
<?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>
keymust be unique among all webspaces. Routes and snippet areas depend on it, so do not change it later.localizationsnames the languages, one of which isdefault. The example website has de, en and nl.default-templatesdefines which template a new home page (home) and a new page (page) get. The home page of the example website usesonepage.templatesassigns special pages: search, error page and the 404 page.navigation/contextsare the menus into which the admin lets you hang pages. The example website hasmain,footer,footer-bottomandlinks.environmentsassign an address to each environment and language. The type (prod,stage,test,dev) is compared withkernel.environment, that is, withAPP_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.
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.