Completly dynamic site


#1

Hello.

I want a dynamic site, without using static files (beside a start page).
All content (html, templates and javascript code) would be stored in the database.
So the users can compose the pages (mainly forms).
Is it possible ?


#2

It’s certainly possible. See meteorpad.com.


#3

You mean the meteorpad application itself ?
Unfortunately it seems not opensource to inspect their code.


#4

This topic:

May help guide your design :smile:

EDIT: This topic discussing orion may also be useful:


#5

Thanks, I will have a look at orion.
But there you still have to define *.js Files (e.g. for defining a collection) ?


#6

Oops, yes, I missed that requirement!


#7

I think what you are trying to do is flawed. You never want users to be able to save raw HTML or JS into your application to do something as simple as generate a form, since that opens you up to infinite security issues and holes.

What you actually need to do is create a page in your app where the user can select options and fields for their form, and then generate a data structure from that. Then, write code that displays the right elements. For example, here is an example data structure you could use to represent a form:

{
  title: "Your favorite cookie example form",
  author: "sashko",
  fields: [
    {
      label: "Your name",
      key: "name",
      type: "text"
    },
    {
      label: "Your favorite cookie",
      key: "cookie",
      type: "text"
    },
    {
      label: "Favorite type of chocolate",
      key: "chocolate",
      type: "select",
      options: [
        {
          label: "Milk",
          value: "milk"
        },
        {
          label: "Dark",
          value: "milk"
        }
      ],
      optional: true
    }
  ]
}

Now, you just need to create a template with some if statements to render the right form elements, and you’re good to go.

I’m like 99.999999999% sure this is how Google forms works, and there is no code involved anywhere from the user’s point of view.

If you want people to be able to compose pages and put forms on them, a good way would be to use Markdown, with a special placeholder for the form, like this:

# My page

This is my page content

%%%FORM-1%%%

Then, when you are rendering the markdown you can replace the %%%FORM-#%%% with the form template.

The point here is you never want to give users more power than they need. If all they need is to write pages with forms, then just have the tools to do that, not a general-purpose programming and templating language.


#8

Thanks sashko. Your post helped me a lot.