Setting Up A Category System In My Application

So just today I’ve started using Meteor(myself being strictly a front-end designer) to try and turn one of my latest creations into a well-built dynamic web application.

The majority of the project is based around a forum structure so I am trying to build a hierarchy between Categories, Forums, and Threads. My current approach is to have separate collections, one for the forums/categories, and another for the threads, and then another for the posts.

My current dilemma is that I’m having an issue(fundamentally) as to how I will call all of the forums under a category. My current structure is setup where each forum has a “parent” set to the ID of the category they go under but I’m just not sure how I am going to go about getting them to display properly organized.

If anyone is willing to help that’d be awesome!

Maybe instead of using the parent attribute for your collection, you could just use an attribute called category anf give it the category you like at the time of insertion of the posts. Then, later, using some algorith, if you make a button to choose show only this or that category, you could call it using the standard syntax:

return Posts.find({ category: "Javascript" });

Well that would work basically the same way as if I just used the parent attribute, my issue is(even if I used a category attribute) how would I display all of the categories with their sub-forums on the index page?

My current approach is to have a {{>Categories}} template, and then inside that template is:

<template name="categories">
	{{#each cname}}
	<div class="category">
		<div class="title">{{name}}</div>
		{{> forums}}
	</div>
	{{/each}}
</template>

And the logic I used to display all of the categories is(type: 0 defines it as a category):

Template.categories.helpers({
	cname: function() {
		return Forums.find({type: 0})
	}
});

Now the {{>forums}} helper I’m just completely stuck on. Here is what the template looks like:

<template name="forums">
	{{#each fname}}
	<div class="forum">
		<div class="ficon"><i class="{{ficon}}"></i></div>
		<div class="fname"><a href="forum.php">{{name}}</a><br><div class="fdesc">{{description}}</div></div>
		<div class="fstats">{{threads}}<br><span class="sub">Threads</span></div>
		<div class="fstats">{{posts}}<br><span class="sub">Posts</span></div>
	</div>
	{{/each}}
</template>

I can get it to show all of the forums, but I am still confused as to how I will make the specific forums show up only under the specific categories in the listing.

Can a forum have multiple categories? Is a thread just a reply to the first forum post?
I don’t exactly understand your requirements so bear with me but it sounds like you need to structure it like this:

4 collections: categories, forums, threads, and comments.

Here’s a example of data for a post on a Meteor forum.

// categories
{
  _id: 'c123',
  name: 'JavaScript'
}
{
  _id: 'c456',
  name: 'Ruby'
}
{
  _id: 'c789',
  name: 'Reactive'
}


// Forums
{
  _id: 'fa23',
  name: "Meteor Forum",
  categoryIds: ['c124', 'c789']
}
{
  _id: 'fa23',
  name: "Ruby Forum",
  categoryIds: ['c456']
}
// threads
{
  _id: 't123',
  createdAt: Date,
  lastPostAt: Date,
  forumId: 'fa23',
  userId: 'u123',
  title: 'Meteor Deployment Question'
  message: 'Where can I deploy my app?'
}


// comments

{
  _id: 'c763',
  threadId: 't123',
  forumId: 'fa23',
  userId: 'u345',
  username: 'JimBob',
  message: "I really like Modulus"
},
{
  _id: 'c869',
  threadId: 't123',
  forumId: 'fa23',
  userId: 'u840',
  username: 'Susan',
  message: "It's all about Digital Ocean!"
}

Then to display the data:

If you’re on a categories page you can fetch all categories and have a link like:

"/forums/fa23" and that would go to the forum page. The forum page would subscribe to all threads with the forumId of fa23 and sort by a lastPostDate timestamp. If you clicked on the thread it would load the thread page and would subscribe to all comments and the thread.

Here’s a nice video on joining three related collections together so you can show them in the client UI:

1 Like

Yes the structure would be very similar to that.
There can be multiple categories(say one for General Discussion), and then each category has it’s own corresponding forums(so under General Discussion would go a Lounge forum). After that all topics(threads) go under each forum, and posts would go inside those topics/threads.

I’m taking a look at that video you linked and it certainly seems to be heading in the direction I need to go. Thanks!