Part 1: setting up the project
By the end of this part, you will have:
- a 4D project
MyBlogwith the BSPK Tools component; - BWEB installed, with a first domain
myblog.test; - access to the BWEB administration with the
DEVaccount; - a
POSTtable for the articles, its dataclass class, and a few test articles.
1. Create the 4D project
- Launch 4D 21.
- Create a new project and name it
MyBlog. - Keep it open locally: the BWEB installation refuses a compiled project or one opened from a remote server.
You can also follow this tutorial in an existing project. In that case, read the section "Installing BWEB in a database that already serves web pages" of Installing BWEB: among other things, the installation changes the On Web Connection database method and the web settings.
2. Declare the component
BWEB ships in the BSPK Tools component, published on GitHub in the bspoke-dev/BSPK-Tools repository. The recommended way is to declare it as a project dependency:
- Menu Design > Project Dependencies.
- + button, GitHub tab, repository path
bspoke-dev/BSPK-Tools. - Pick a specific version (a tag), confirm, then restart 4D.
On restart, 4D downloads the component, which brings the 4D components it needs by itself. Copying the component into the project's Components folder also works, but do not do both. Details are in Installing BWEB.
3. Install BWEB
- Run the
_BSPK_LAUNCHmethod: the component's launcher opens. - Click BWEB. The Before installing screen lists what the installation will change in your database. Read it, then click I have read these changes and I accept them.
- Accept the licence, then click Start installation. The wizard ticks its steps as it goes.
- At the SSL certificate step, give your
cert.pemandkey.pemfiles, or continue without a certificate for a local trial. - 4D restarts during the structure step: this is expected, the installation resumes by itself.
- When the wizard asks for the name of your first domain, enter
myblog.test. It is a host name: nohttps://, no port, no slash. - Accept adding this name to the machine's
hostsfile, so thatmyblog.testanswers locally. This change requires administrator rights; if it fails, a message gives you the line to add yourself.
Your structure now contains many
BSPK_*tables: they belong to BWEB. Do not delete or rename them.
4. Log in to the administration
- In the launcher, click Test BWEB: the browser opens
https://myblog.test/bweb. - Without a certificate, or with a self-signed one, the browser shows a security warning: you can proceed for a local trial.
- The installation created an account whose login is
DEV, with no password. The first time you log in asDEV, BWEB asks you to choose the password and confirm it. - You land on the BWEB administration.
The DEV account belongs to the system group: it holds every right, including the right to edit pages with the dev panel.
A fresh installation starts in DEV mode (
DEV_PARAMETERSparameter file). That is what you want while developing; on a production server, deleteDEV_PARAMETERSandPREPROD_PARAMETERS. See The parameter files.
5. Create the POST table
Back in 4D, open the structure editor and create a POST table with the following fields:
| Field | Type | Index | Role |
|---|---|---|---|
uuidKey | Alpha, UUID format, auto-generated | Yes (primary key) | Article identifier |
title | Alpha (255) | Yes | Title |
slug | Alpha (255) | Yes | Readable address of the article, computed from the title |
summary | Text | No | Summary shown in lists |
content | Text | No | Full content, as HTML |
isPublished | Boolean | Yes | Draft (false) or published (true) |
publicationDate | Date | Yes | Publication date |
uuidKeyas primary key: this is the convention of BWEB tables, and this key will identify the article in the address of the editing page.sluggives the public blog readable addresses:/article/my-first-articlerather than an identifier.isPublishedlets you write drafts: only published articles will appear on the public blog. Give it the property that rejects NULL values (never_nullin the catalog): a NULL boolean is neither true nor false for anIf.
Save the structure.
6. Create the POST dataclass class
The functions your buttons will call live in the table's dataclass class: the file Project/Sources/Classes/POST.4dm. Create it; for now it only holds its declaration:
Class extends DataClass
The Class extends DataClass line matters: in an event's class list, the dev panel only offers classes that extend DataClass, Entity, EntitySelection or WebFormController.
Optional: classes generated by BWEB. The
BSPK_UTIL_UPDATE_DATACLASSmethod can create thePOST,POSTEntityandPOSTSelectionclasses for you and inject BWEB's base code into them (change history included). For your application's tables, it only does so when thevb_AddBSPKDataClassparameter is true in thevo_Paramof your parameter files. The injected code sits between the/*** START BSPK ***/and/*** END BSPK ***/tags and is rewritten on every pass: write yours outside them. If the method creates classes, it restarts 4D. This tutorial does not need it.
7. Add a few test articles
To have data to show as early as part 2, run this code once, in a method or with the launcher's code execution button:
var $post : 4D.Entity
var $i : Integer
For ($i; 1; 3)
$post:=ds.POST.new()
$post.title:="Test article "+String($i)
$post.slug:="test-article-"+String($i)
$post.summary:="Summary of article "+String($i)
$post.content:="<p>Content of article "+String($i)+".</p>"
$post.isPublished:=($i#3) // the third one stays a draft
$post.publicationDate:=Current date-$i
$post.save()
End for
To browse or fix this data from 4D, the launcher also opens the ATL, the component's table browsing tool.
8. Check
Before moving on, check that:
- the login page of
https://myblog.test/bwebshows up, and you can log in asDEV; - the
POSTtable exists with its seven fields, and holds three articles; - the
POSTclass exists and starts withClass extends DataClass.
Next: Part 2: the back-office.

