I have a template that shows a table of posts. The user can edit, add, and delete posts. My site has two different varieties of posts: it has a shared library of posts and each user has posts attached to their profile.
My table is the same across the site, but the CRUD operations are different based on whether it's displaying the user's posts or the site's shared post library. For example, when a user adds a post, I need to run Meteor.users.update({_id: [user ID]}, {$push: {'profile.posts': postObject}})
. When the site admin adds a post, I need to run Articles.insert(postObject)
.
What is the best way to do this? I tried passing an argument to my template inclusion (i.e. {{> postsTable source=Articles}}
) and testing for that in the event functions, but it seems this replaces the data context which means my template can no longer get to the posts. I also thought about testing the current route and using that to branch the event functions, but that method seems a bit smelly.
Alternatively, I could bind events for the templates that include the table rather than on the table template itself. This is probably the simplest solution, but I would be duplicating a lot of code across those various templates when the only thing that changes is how the resulting data is stored.