Jump to content

How to create reading book site with ProcessWire?


Hector Nguyen
 Share

Recommended Posts

Hello PW-ers,

I'm a newbie to this CMF, and totally fallen in love with this sexy framework. I knew that ProcessWire documented very well, but nothing is faster to handle a new framework than building a new project.

The application (reading online book) I want to build will be same like normal CMS but,

It should have fields / entities like this:

  • Books
  • Books > Chapters (a book may have over thoudsand of chapters)
  • Authors
  • Publishers
  • Posters (Book may be uploaded by any registered members)
  • Images (Thumbnail, it should be picked and uploaded via input type=files)
  • Rating (a book can be rated by readers, like any forum software rating system, in social networking world this aka Likes)
  • Date created / updated

Please suggest/guide me how to create and maps fields (or what is this call) in ProcessWire like above description.

I still don't understand the connection between fields (in backend) between variables (how to use it) in template, please give me few example if possible.

 

Any help would be appreciated,

Hector.

Edited by Hector Nguyen
grammar fixes
Link to comment
Share on other sites

Hello,

Here is some theoretical background to start with:

How to actually setup parent/child(ren) relationships:

Best general introductory tutorials:

http://blog.mauriziobonani.com/processwire-basic-website-workflow-part-1/

https://www.smashingmagazine.com/2016/07/the-aesthetic-of-non-opinionated-content-management-a-beginners-guide-to-processwire/

 

If you already have a little bit of developer backgound, I recommend checking out this profile:

 

Even if you do not want to deal with the "Wire Render Pattern" implemented for the front-end, checking out the templates/fields of the profile demonstrates a great deal about how to set things up.

  • Like 5
Link to comment
Share on other sites

Hello @szabesz,

Thanks for replying to my topic, as far as my understanding now. All fields are belong to a template, so I can add as much as possible fields to the template right? And in my case, I may have 2 templates, one is book and the other is chapter. I may have template to manage the categories too, because book should be manage under categories.

So it will look like this in my imagine:

CATEGORY TEMPLATE

Category
├── Title
├── Static Block
└── Thumbnail

BOOK TEMPLATE

Book
├── Title
├── Author
├── Publisher
├── ISBN
├── Type (traditional or comic)
├── Rating
└── Thumbnail

CHAPTER TEMPLATE

Chapter
├── No (number of chapter)
├── Title
├── Content
├── Rating (This will affect to rating of the whole book)
└── Thumbnail

 

Everything in PW managed by Pages. So for example,

I created a new page with name "Hacking & Security" (Category), another one page is child of "Hacking & Security" name "The Art of Deception" and another one is child of previous name "Chapter 1: Introduction" ?

It also mean I have to create all chapters of that book as a child page of "The Art of Deception" ?

 

Question 1: Is it possible of creating child of child as I demonstrate above? (Category > Book > Chapter 1 ... N)

Question 2: Is it possible to force user must create content of book (at least 1 chapter) whenever they create a new book? I'm looking for a way to create a new admin page to manage books which separate to default "Pages" section, can I ?

Question 3: Is it possible to set book page status like Draft, Publish, Under Review...etc ? Is that a field?

Question 4: I checked in PW template, and I saw something like $page->title, how is that possible? PW can use name of fields in template without defining it?

 

Thank you once again,

Have a good day.

Link to comment
Share on other sites

As a simple example, let me show you the basic setup of a blog (simplified diagram of the blog profile I recommended above):

pw-relationships.png

It is a "UML like" diagram, where the yellow boxes are the templates, the blue ones are sample pages (they must be created in the Page Tree) based on the templates. Generally speaking whenever you can, you should set up parent/child relationships, because this is something ProcessWire handles well, out of the box. However, it is not possible to force all the required relationships into a tree, so we can also have "simple" one-to-one and one-to-many relationships via Attributes (Fields). A Field in ProcessWire has its associated "Input field type" (found under the Input tab of the field), which sets up the UI element used by the admin for the field. Quote: "Input field type: The type of field that will be used to select a page. Select one that is consistent with the single page vs. multi-page needs you chose in the "details" tab of this field..."

Hope this helps. If not, I can mock up a similar diagram about your use case too.

Answers to your questions:

A1. Generally yes, but I recommend implementing something like you see above: parent/child for Books/Book, Categories/Category, Chapters/Chapter, etc.. and you can connect these via Attribute (Field) / InputField relationships. This is a much more flexible setup.

A2. If I understand you correctly, you can do it if you use Attribute (Field) / InputField relationship, and by setting the field to "required".

A3. Yes, a field. The simplest way to implement it is using the Options type:

Of course, you can also setup just another Field/InputField relationship, if you need more than a simple select.

A4: Sure, it can: https://processwire.com/api/variables/

BTW, one more reading on the topic: https://medium.com/@clsource/understanding-processwire-templates-fields-and-pages-201aecd0a1a4#.gd0w6u9qw

 

Edited by szabesz
typo
  • Like 5
Link to comment
Share on other sites

  • 2 weeks later...

Hi @szabesz,

As my understanding, you recommend me to use one-to-many to solve relationship in my case, right? But there are two things confusing me right now:

  • How does Chapters/Chapter make sense in my case?
  • Because there are thoudsand of chapters for a book, so if I use relationship like Chapters/Chapter, it mean one "Chapters" template contains million of "Chapter" templates. How can I living among them?

Quite confused to me :(

Link to comment
Share on other sites

Ok it is may confusing while you have the UI in mind...i would present you a different view.

Basically you are right. You can setup your app like you wrote:

->book
-->chapter1
-->chapter2
...

as childpages of the book. As oneToOne every chapter belongs to only one book.

In the blog example of @szabesz a blogentry chould change tags, cathegory and so on but your chapters always belongs to one book...

So you could use something like to easy edit the childpages (chapters) of a book:

On the API side you can check if a book have a childpage (so a chapter is there) and only if this check is true show the book...on the admin you can show the editor a message with a hook on page save that there is no chapter and they have to create at least one...

Example for hooking after page save:

 

 

UI Alternative1 (The real problem with PW is that there are tons of alternative ways to go....at the start; - )

You could take a look at the great Table field from the Profields - it is commercial but have a lot of pros on User UI and datamanaging of such setups. It uses pages in the background but as fieldtype you could add items within the book template.

Have a read:

https://processwire.com/api/modules/profields/table/

https://processwire.com/blog/posts/fieldtype-pagination/#example-profields-table

https://processwire.com/blog/posts/3.0.27/#whats-new-in-profields-table-v14

UI Alternative2

Use PageTable field for your chapters. It uses pages, too and your editors add entries on the book template, too. It could be easy set to put  the chapters as childpages or under chapters/chapter for managing all under one root. The pages stay connected via the PageTableField.

PageTable Field is a little bit different to Table since you can setup more complex editing things and change the single pages on the default edit path, too.

Table and the default Repeater field are both repeater fields for less or more complex entries that belong to one page, while only the table field provide the options that you need (hundreds or thousands of chapters of a book) pagination, filtering, scalability and so on.

PageTable and the former mentioned Repeater Matrix are something like a provided UI for editing real pages with templates and fields without restrictions.

Take a deeper look:

On the first projects with PW take the time that you will save while developping to research how to start since this time is priceless.

While you get deeper in the rabbithole the more fun you will have ;)

best regards mr-fan

  • Like 4
Link to comment
Share on other sites

1 hour ago, mr-fan said:

Use PageTable field for your chapters.

I think PageTable (and Repeater / Repeater Matrix) will not scale up to the number of chapters expected.

But if chapters are child pages of a book then the Lister mode of Batch Child Editor would be a good way to sort/find/manage large numbers of children:

On 14/04/2014 at 5:48 AM, adrian said:

Lister - Embeds a customized Lister interface. Installation of ListerPro will allow inline ajax editing of displayed fields.

  • Like 4
Link to comment
Share on other sites

@Robin S is right - you wrote tausands of chapters on one book....than i forgot one really big additional option in managing chapters right for editors....;)

https://processwire.com/api/modules/lister-pro/

With lister you can setup a view where someone can select the book - or search for it and CRUD chapters...

The Profield Table can paginate, filter and sort, too so this would scale for many chapters.

But one the first run i would give book/chapters a go and use BatchChildEditor.

With BCE you could create dummy data, pages via CSV import, too!! Thats the propose i use it in some projects.

Most important thing choose wise and have fun! ;)

  • Like 3
Link to comment
Share on other sites

Thanks to @mr-fan and the others :)

It's more clearly to me now, so I may have Categories/Category, Books/Book but Chapter will standalone?

I also taking a note and stick it into my screen: "Pages is everything in PW".

 

Thank you (all of you and yes you) once again,

I'm trying it right now and will come back soon :)

Edited by Hector Nguyen
Return key should be removed from the keyboard.
  • Like 1
Link to comment
Share on other sites

2 hours ago, adrian said:

Definitely 3!

Since the preparation for 3.x release is already underway, see: https://processwire.com/blog/posts/pw-3.0.32/ 

And of course, the 3.x line is the future, the 2.x line is "just" there to ease the switch and give enough time for developers to decide how to switch from 2.x to 3.x. One can either upgrade or wait until upgrading becomes feasible, if at all. But Ryan has explained it a lot better than me :)

 

  • Like 1
Link to comment
Share on other sites

Will all plugins from 2.7.x or 2.8.x will works on 3.x version? In the plugin directory I saw only few plugins compatiable with 3.x, that is why I asked 3.x or 2.x.

Another question is can I manage my own plugin via composer? Or can we install ProcessWire via composer? For some not so secret reasons, I marriaged with Composer :'( 

Link to comment
Share on other sites

2.7 modules will probably be compatible with 2.8/3.0. There are only some small points which could require an update to fully make a module compatible with both versions. Backwards compat is another topic and depends on if one is using namespaces or other new features.

On 2.8/3.0 you can install modules via composer which are set up to be used that way and installation of processwire via composer is planned.

Link to comment
Share on other sites

6 hours ago, Hector Nguyen said:

Will all plugins from 2.7.x or 2.8.x will works on 3.x version? In the plugin directory I saw only few plugins compatiable with 3.x, that is why I asked 3.x or 2.x. 

https://processwire.com/blog/posts/processwire-3.0.14-updates-file-compiler-fields-and-more/#file-compiler-updates

6 hours ago, Hector Nguyen said:

Another question is can I manage my own plugin via composer? Or can we install ProcessWire via composer? For some not so secret reasons, I marriaged with Composer :'( 

https://processwire.com/blog/posts/composer-google-calendars-and-processwire/#processwire-and-composer

https://processwire.com/blog/posts/happy-new-year-heres-a-roadmap-for-processwire-in-2016/

"Composer support. While we already have partial composer support in the current devns branch, we still have more work to do in this area before we start documenting and highlighting it."

https://processwire.com/blog/posts/multi-instance-pw3/

"PW3 isn't yet up on Packagist, but will be after it's in master release."

Hope this helps.

  • Like 1
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

×
×
  • Create New...