You are currently browsing documentation for Diem 5.1 - Switch to version5.0

2. Your first project with Diem

So, what kind of project are we making?

The Diem Ipsum project's ultimate goal is to help you, the users. That's why we won't actually set a clear goal for now, but instead we will look forward to requests for features and modules from the community and show you how to build them with Diem. This means that the project we are building has to be flexible and have the ability to evolve in new, unpredictable ways.

You know, just as is the case with most professional applications in the real life ;)

Installation

Diem Versions

There are two ways of installing Diem - from the official package or through Git. Let us briefly discuss the differences:

If you are using the official package, you will notice that it comes with the latest stable version of symfony already included. That is because, as you already know, Diem depends on symfony. In contrast, the Git will hold the latest Diem improvements (which may be unstable) and will contain an externals entry to the symfony trunk (again, which may be unstable). Which version you use is entirely for you to choose, however we would recommend sticking to the official package when working with production servers.

Creating the Project Directory

Now that you have selected your version of Diem, let's create a directory to hold all the files:

Installing Diem

The Diem lib files can be placed anywhere you like, so that you can have a single instance of the Diem installation used by many projects, or have Diem embedded into each separate project. We are going to show you how to do the latter, installing Diem in lib/vendor/diem:

mkdir -p lib/vendor
cd lib/vendor

You now need to download the latest version of Diem into your new vendor directory. There are several ways to do this, all described on the Downloads page in the docs, but here are two options for this tutorial.

That's the end of options for the moment. You should be in the root of your new project directory (/home/diemprojects/diem-ipsum in our example)

Now we will run the Diem installer. It will automatically perform a requirements check and inform you of any potential problems, after which it will guide you through the initial Diem setup.

php lib/vendor/diem/install

For the more curious of you, what this command does is initiate symfony's project:generate task with Diem's custom installer script.

Installation Notes
Windows users will be prompted to run php symfony dm:setup after the initial installation has completed; This is due to limitations of the Windows platform.
Follow these links and learn more about the Installation and Requirements.

Almost finished...

Before we dive into Diem layouts, download the following sample images into the diem-ipsum/web/uploads directory

Congratulations, Diem is now installed!

It was easy, wasn't it? With just those few simple steps you have a running Diem installation! Two applications have been created, a publicly accessible front and a secured back-end admin (you can log in now with the password from the installation at admin_dev.php and look around).

Building layouts with Diem

We are now going to learn how to build layouts with Diem's front JavaScript console, but before we do that we need to have a design. The coolwater style from styleshout is free and suits our needs perfectly.

Set up the theme

Diem allows you to easily set up themes for your applications. Let's do that now for the CoolWater theme. First download the theme archive and extract it to web/themeCoolWater. Then open the apps/front/config/dm/config.yml file and set the contents as follows:

Since we have implemented a theme for our site, Diem will look for the stylesheets layout and typography in the web/themeCoolWater directory.

Layout setup

When developing with Diem, you do not need to deal with layout.php - the generation of clean and semantically sound x/html is handled internally. What you will be working with is Diem's own layouting system, which consists of two components: page layouts and widgets.

When you create your project, Diem will automatically create this layout for your pages:

The default Diem pageSuccess.php layout is split into five Areas:
layout.top, layout.left, content, layout.right and layout.bottom.
The purpose of Areas is to contain widgets.
Areas prefixed with "layout." can be reused by several pages; Areas prefixed with "page." are specific to the page.
Each widget is actually a simple symfony component rendered through a partial.
You set up these widgets through an intuitive visual interface, but more on that later.
Diem comes bundled with the most often used widgets and you can easily extend it with your own.
To learn more about this read the Diem layout documentation.

Using Diem widgets

As we said before, Diem widgets are basically symfony components with partials. The difference with symfony is that in Diem you can drag&drop these widgets directly onto the page (inside layout Areas) using the user interface of Diem, instead of including them programatically. This helps streamline the process and has the added benefit of seeing the results in real time.

Invoking the layout interface
To get to the front application layout building interface, first log in to the admin panel at localhost/admin.php and then click on the "Go to site" link in the tool bar.

First, a quick word about the zone widget. This widget represents a simple separator (a div to be specific). Just use it as you would use a normal div tag. Also, a zone is automatically created for every Area defined in a layout, so don't be surprised when you open the supposedly empty project and there are zones are already included ;-)

By default, new projects contain a main/header widget. This means the partial is located on the main module, and it's filename is _header.php. Let's add this widget to the page. Invoke the layout interface and click on the "Add" button in the toolbar at the bottom of the page:

The "Add" menu contains a list of all widgets you can append to the page. Find the main/header widget and drag it around. Then drop it on the top Zone.Drag the header widget:

Now drop it on the top zone. This will open a window in which you can customize the widget. For now, leave it blank and click the "Save and close" button.

Similarly, drag&drop the main/footer widget to the bottom zone.

The result:

To toggle OFF the editing mode and see what this looks like for the end user, click the magnifier button on the lower tool bar:

Writing the site name in the header widget

What good is a website without a big and nice title?

Open the header partial inapps/front/modules/main/templates/_header.php
And append the following code inside:

This code uses Diem template helpers. The _tag() function writes a x/html element. Its first argument's syntax is exactly like a CSS or jQuery selector, allowing you to set the tag/class/id all at once. The second argument is the content of the element. You will see this function used a lot throughout the Diem Ipsum project.

In this example

echo _tag('h1.t_site', _link('@homepage')->text('diem ipsum'));

will output

<h1 class="t_site"><a class="link" href="/">diem ipsum</a></h1>

Helpers
Diem template helpers expand upon the symfony approach.
They make templates cleaner and more concise by removing the need to open and close several PHP tags. By using the CSS and jQuery syntax, they standardize HTML manipulation. And they will always output XHTML Strict compliant code.
Their usage is recommended, but not required.

Yes, we are using plain HTML because for now the footer doesn't need dynamic content. When you first open the template it will have an opening php tag - don't forget to remove it.

The result of today's work

We have learned how to set up Diem and are well on the way to building our first Diem project. We now have a grasp of Diem themes, templates, widgets and helpers. Tomorrow we will tackle page creation with Diem, but for now let's take a step back and look at what we have accomplished: