Create a helper to access URL query param values

I suggest to create a helper to access URL query param values.

Example:

I have link like below,

/resources/?type=case-studies

Now i want to access that query param value on like below,

<p>Selected type is {{query_param.type}}</p>

That feature would require careful use to avoid problems. For example, in your case, I could create a a URL to your site like:

/resources/?type=Buy%20Diet%20Pills%20%at%www.fake-diet-pills.com

Now I’ve created a link to your website which causes it to advertise my fake diet pills website.

The safe version of this pattern is to validate all the query parameters strictly or not pass the query params directly to a place where they are displayed.

It would be easy for theme designers not versed in security best practices to easily introduce some insecure practices with this feature.

@markstos How to manage complex filtering without query params in ghost ?

I have following URL, how i can filter posts according to the given values ?

/cources/?q=free&type=diploma,degree&tag=science,mathematics,english

I know how to full fill the requirement using Ghost API and client side scripting. But, its not good to SEO. That is my actual problem.

Maybe making careful use of a helper that accesses the query string is the best way to go, or using frontend JavaScript to read them and making Ghost Content API calls.

@Cathy_Sarisky may have some better ideas.

@markstos If i use Ghost Content API call with front-end JS, How to crawl that posts links when doing SEO ?

At least the Google bot DOES parse JavaScript, so it’ll index your page, regardless of how you build it.

2 Likes

Because of the popularity of frameworks like Angular and React that use APIs and JavaScript to build pages, search engines started to render pages like a browser would to index them.

1 Like