Just starting out

Hey fellows. I need a little help.

I would like to create a CMS with Elm. My models are: Page, Section and Block.

Each model has three fields: a slug, a name and a description.

Page has a field called sections (type: List Section).
Section has a field called blocks (type: List Block).

How would YOU spread the data across files?

I thought to create four files:

  • Main.elm
  • Page.elm
  • Section.elm
  • Block.elm

Is that wise and recommended? And where should I place all the forms and the form state?

Thank you.

The general suggestion is to organize files (modules) by a central type. My approach is also to keep everything in a single file until it feels too large and then I’ll move 1 or 2 types out into their own module (along with related functions).

I’d also recommend checking out Elm Europe 2017 - Evan Czaplicki - The life of a file - YouTube and it goes over how to structure your modules/files a bit.

2 Likes

Thank you for the quick reply. :grinning:

I am still searching for an answer on how to layout a file encapsulating a form for — let’s say — the Page Model. Any thoughts?

There are packages, like dillonkearns/elm-form, for helping with forms. If one of those packages doesn’t fit your needs then I think I’d need a little more details about what you’re looking for. I’m not really sure what a form for a Page Model really means in this context.

Welcome to elm! :slight_smile:

One advice would also be to not overthink it at the start. In many languages you need to get your architecture “right” from the get go. In Elm though it’s usually very cheap and very safe to refactor your code in even the largest ways.

So if that’s something you’re comfortable doing, i would suggest you just start out and put something down within the very basic elm architecture. Do not look left and right at packages that might help because they might also just confuse you even more. The very basic elm program is easy to get into simply because the architecture and the code is so self-explaining and explicit.

Have fun!

3 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.