Template Builder
I built most of it, from the proof of concept to the release: the core, the drag and drop and the rules of the grid. The hard calls, like how rows and columns render, we made as a team.
Why it exists
In dotCMS, templates shape the layout of every page. The old Template Builder was unreliable and clunky. I liked the project, so I took the initiative.
We chose Gridstack for drag and drop. Its docs had gaps, so I read its source code to learn how to use it, and built the builder on top: rows and boxes, containers, styles, a sidebar, and autosave.
Key decisions
-
Research, a proof of concept, then the architecture
Before building, we researched the options and turned the result into a proof of concept. On it I set up the architecture the whole feature grew from: a store for the builder's state, and a parser that turns dotCMS's data into the builder's own model.
-
Detecting a full row
To know whether one more box fits, the builder draws each row as a 12-character string, one character per column, and a regular expression looks for enough empty columns side by side. A full row turns itself off before you drop a box that wouldn't fit.
-
Breaking out of the library's limits
Where Gridstack fell short, I worked around it from the inside. For example, it lost a new box's size while you dragged it, so the builder puts it back as the pointer moves.
See it work
The hard part
Making it work took cleverness. The library wasn't easy, and some of what we needed it didn't do, so the core was me hammering nails until it held.
A really fun project. I learned a lot, and I still keep the proof of concept.
Where it is now
Fully shipped. It runs in its own Templates portlet and inside UVE.