Jump to content

How to store data


Melvin Suter
 Share

Recommended Posts

Hi there

 

I've been wondering, how to do this the right way... How do you store data? For example:
I've created a recipe-book for myself. Every recipe is a page. Inside those recipes I've got a textarea with instructions and I need to have a list/table with ingreadiants and amount. Right now I'm using a yaml-field, as it is the easiest way. But is there a better/correcter way to store data like that? Or as a better example, if you have a page and want comments to that page?

Basically it's just the setup where yo have items/pages with multiple sub-entries with multiple values.
Do I write a module/template which access the database directly over the $database API and create my own table? Or do I create sub-pages to that page for each entry? Or do I use yaml-fields?

I get that normaly a page would be the primary data-entries. But with time that would make the tree quiet bloated, wouldn't it?

 

Thanks and Regards

Link to comment
Share on other sites

Hi,

From the top of my head this could do it this way :

a template with a title and body (recipe) field and a repeater field to hold the ingredients list :

a text field to hold the ingredient name

a text field to hold the amount of ingredient

a select field to hold the amount unit (tsp, l, ml? etc..)

  • Like 1
Link to comment
Share on other sites

There are so many ways in ProcessWire to do or save things.

Depending on your background and history with ProcessWire you will find other ways or solutions.

I know recipe-collectors that would only need two fields. A title and a textarea.

I personally would go a more abstract way to be able to much more and other things.

  • Template: Recipe
    • Fields:
      • title (text)
      • summary/introduction (textarea)
      • preparation (textarea)
      • ingredients (repeater)
        • Fields:
          • ingredient (page reference - pages with template ingredient)
          • amount (int or text)
          • unit (select options - grams, cups, liters, hint)
      • images (image)
  • Template: Ingredient
    • Fields:
      • title

With that setup I can easily collect all my recipes, create a list of all ingredients I need for all of my recipes. Can look for recipes with a special ingredient and so on.

  • Like 5
Link to comment
Share on other sites

1 minute ago, wbmnfktr said:

There are so many ways in ProcessWire to do or save things.

Depending on your background and history with ProcessWire you will find other ways or solutions.

I know recipe-collectors that would only need two fields. A title and a textarea.

I personally would go a more abstract way to be able to much more and other things.

  • Template: Recipe
    • Fields:
      • title (text)
      • summary/introduction (textarea)
      • preparation (textarea)
      • ingredients (repeater)
        • Fields:
          • ingredient (page reference - pages with template ingredient)
          • amount (int or text)
          • unit (select options - grams, cups, liters, hint)
      • images (image)
  • Template: Ingredient
    • Fields:
      • title

With that setup I can easily collect all my recipes, create a list of all ingredients I need for all of my recipes. Can look for recipes with a special ingredient and so on.

+1 for the ingredient template allowing to create a ingredient database.

  • Like 1
Link to comment
Share on other sites

2 hours ago, wbmnfktr said:

There are so many ways in ProcessWire to do or save things.

Depending on your background and history with ProcessWire you will find other ways or solutions.

I know recipe-collectors that would only need two fields. A title and a textarea.

I personally would go a more abstract way to be able to much more and other things.

  • Template: Recipe
    • Fields:
      • title (text)
      • summary/introduction (textarea)
      • preparation (textarea)
      • ingredients (repeater)
        • Fields:
          • ingredient (page reference - pages with template ingredient)
          • amount (int or text)
          • unit (select options - grams, cups, liters, hint)
      • images (image)
  • Template: Ingredient
    • Fields:
      • title

With that setup I can easily collect all my recipes, create a list of all ingredients I need for all of my recipes. Can look for recipes with a special ingredient and so on.

I actually did exactly as wbmnfktr suggested in a previous project (still in development). At first I was a bit hesitant of having to create new ingredients every time I wanted to add a new unique recipe, but the pros quickly outweighed the cons. It makes filtering on the front end a lot better/easier, as well as makes new recipes easier.

  • Like 1
Link to comment
Share on other sites

Allow creating new pages from page reference field and ingredients aren't a thing anymore.
Add autosuggest and everything is fine.
I actually imported lots of ingredients before. So authors typed bro... and they got broccoli already. Less typos. Perfect.

I clean up once in a while but that's a matter of minutes now.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...