Melvin Suter Posted March 1, 2019 Share Posted March 1, 2019 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 More sharing options...
Nicolas Posted March 1, 2019 Share Posted March 1, 2019 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..) 1 Link to comment Share on other sites More sharing options...
wbmnfktr Posted March 1, 2019 Share Posted March 1, 2019 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. 5 Link to comment Share on other sites More sharing options...
Nicolas Posted March 1, 2019 Share Posted March 1, 2019 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. 1 Link to comment Share on other sites More sharing options...
wbmnfktr Posted March 1, 2019 Share Posted March 1, 2019 Correct. Ingredient database and therefore filters/presets. Link to comment Share on other sites More sharing options...
louisstephens Posted March 1, 2019 Share Posted March 1, 2019 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. 1 Link to comment Share on other sites More sharing options...
wbmnfktr Posted March 1, 2019 Share Posted March 1, 2019 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 More sharing options...
Melvin Suter Posted March 1, 2019 Author Share Posted March 1, 2019 Wow. First of: thanks to EVERYONE. That's a greate community!!! Secondly: I'll have to look into your answer. I didn't knew you could create repeater fields. Something learned here. :) Thank you all for those fast and informative answers! Link to comment Share on other sites More sharing options...
wbmnfktr Posted March 1, 2019 Share Posted March 1, 2019 Repeaters are kind of awesome. https://modules.processwire.com/modules/fieldtype-repeater/ You have to install repeater and select options (maybe even page reference - I'm not sure about them) first in order to use them. You will find them under /youradminurl/module/ (Core tab) - look for repeater, select options and page reference. Link to comment Share on other sites More sharing options...
wbmnfktr Posted March 1, 2019 Share Posted March 1, 2019 If you @Melvin Suter or everyone else wants to play around with a recipe site profile: https://github.com/webmanufaktur/pwrecipes It's by far not complete or a ready-made website but it shows some things I mentioned in first anwer here. 8 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now