How to display data from another collection?


#1

Hi all :blush:

I’m new to Ghost and currently researching building a custom website on the Ghost platform for a client.

Using the example of a law firm website. Say I’m displaying an article from the litigation category and within that post I want to display a list of lawyers (another collection) who specialise in litigation.

As far as I know from the documentation, I need to pass data to a filter that displays a specific list of authors (lawyers that specialise in litigation).

Does Ghost support custom tags for different authors, or is there a work around for this.

I don’t have an example to show as just researching at the moment, but if someone could let me know how this can be done in Ghost it would be much appreciated :pray:


#2

Say I’m displaying an article from the litigation category and within that post I want to display a list of lawyers (another collection) who specialise in litigation.

To be clear, are you asking about displaying a list of authors who specialise in litigation, or a list of posts by those authors?


#3

yes i also want to know this hope is there anyone who can help me out too.
with regards
miles smith
notepad.software vidmate filezilla.software


#4

Hi Hannah,

Thanks for the message. Sorry for the unclear post :sweat:But yes, I want to display a list of authors who specialise in litigation - so I guess creating tags for different authors (i.e litigation, contract etc.)

Hope that makes sense now.

Thanks


#5

Not to dismiss your usecase at all, tagging authors is not something that Ghost supports just yet.

You would need to hardcode the slugs of the authors, at least until we add this feature. Using partials, it should at least be possible to only hard code the list once per group of authors.

e.g. First create a template to cover as much of the shared logic for outputting authors as possible

# File: `partials/authors-list.hbs`
{{#foreach authors}}
<div> 
  <h3>{{name}}</h3>
  ...
</div>
{{/foreach}}

And then, for each fake tag, you can create a minimal partial to hardcode the list of slugs:

# File: `partials/authors-tag-litigation.hbs`
{{#get "users" filter="slug:[jo,fred,emma]" as |authors|}}
    {{> "authors-card"}}
{{/get}}

And for now you’d use this like

{{> "authors-tag-litigation"}}

I know it’s no fun to maintain this, but at least once the feature is added you will be able to refactor it out quickly by doing:

# File: `partials/authors-tag.hbs`
{{#get "users" filter="tag:[{{tag}}]" as |authors|}}
    {{> "authors-card"}}
{{/get}}

And use it like {{> "authors-tag" tag="litigation"}}


#6

Hi Hannah,

Thanks very much for the quick reply, this certainly is a work around and I was thinking of something similar but didn’t come up with as simple solution as this.

So finally is this a feature that will be released anytime soon?

Thanks again :pray::blush:


#7

We don’t do ETAs, but it’s definitely something we’ve got on our radar.


#8

Great, thanks for the update and the help. Will be sure to post on here if I have any issues with the above integration.


#9

Hey :blush:

You can check the below workaround for more info on this :+1:


#10

Have a feeling there’s some spam there… :slight_smile:


#11

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.