Passing key/value pairs as data in routes?

Is it possible to pass key/value pairs as data to a template in a custom route?

Essentially, this sort of thing (but this doesn’t work):

routes:
      /welcome/: 
        template: welcome
        data:
          foo: bar

Thus in the template, {{foo}} renders to bar?

Thanks!

Hey @Jeremy606 :wave:

You can’t do something like that at the moment. Do you mind sharing what you’re trying to do?

1 Like

I really wish you could but I don’t think it’s possible.

Thanks, guys. @vikaspotluri123, basically we are trying to abuse Ghost and perhaps make it something it is not. :slight_smile:

We are using Ghost to deliver educational content for remote learning during the COVID-19 isolation. We use tags to associate posts with a given “class” as well as a specific audience group. (Basically, you could think of classes as having different sections-- some posts are all sections of a class, some for only specific sections).

We’ve made this work by creating a custom route and template for each combination of class+section. If we could have passed parameters to routes, this would have eliminated the need to create so many template files-- instead we could have just use one parameterized template.

Thanks for the help!

1 Like

You’d be better off using Ghost as a headless CMS and building a FE app/static pages instead for your use case.

I’m also working on an educational website using Ghost. My approach is to use channels for most routes as they do not intervene with anything. It works perfectly, but I ran into one big problem: I had a lot of routes, which caused ghost (or express) to give error 500. I reported a bug, and I’m currently trying a workaround. If it works, I’ll let you know.