algolia / instantsearch

⚡️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/
MIT License
3.72k stars 522 forks source link

Expose Hogan options #99

Closed Jerska closed 9 years ago

Jerska commented 9 years ago

Shopify assets already use a templating engine called liquid in the back-end with the same delimiters as mustache ({{ }}). This is the only way Shopify user's can use their Shop configuration to adapt the design of a template for example. This is why I've made our templates also liquid files, so I have for example a snippet/autocomplete_product.hogan.liquid.

Hogan exposes an option to change its delimiters, it's done like this:

Hogan.compile('...', { delimiters: '[[ ]]' });

This options can't be global to Hogan, so you have to give them to each Hogan.compile. It would be great if we could have a hoganOptions parameter in the constructor of instantsearch.js.

If that's ok with you, I can probably do the PR myself.

vvo commented 9 years ago

I do not understand why having liquid in the backend requires you to change hogan options in the frontend.

Maybe i am missing some info.

redox commented 9 years ago

Maybe i am missing some info.

Yes because the hogan templates are defined in liquid files :) So while rendering the page, the hogan {{ }} are interpreted as liquid tags :/

redox commented 9 years ago

That being said @Jerskouille, not sure how to deal with the default templates that are actually using {{}}, could that be overridden on a case by case?

Jerska commented 9 years ago

Oh yes, right, it wasn't really clear, I've updated my first message. About your last question @redox , I hadn't thought about it. Maybe don't use the specified options if 'template' isn't specified, but it doesn't feel right.

pixelastic commented 9 years ago

Jekyll also uses Liquid, and I had to use {% raw %} and {% endraw %} to be able to write Mustache inside Liquid. I don't know if this is a default Liquid tag or a Jekyll one, though.

https://github.com/pixelastic/blog.pixelastic.com/blob/master/app/_layouts/default.html#L72-L81

I feel that this will be a better way of handling the issue than changing the Hogan config.

Jerska commented 9 years ago

I believe it is liquid related, since this also works in Shopify, but having to put it all the time tends to get messy, and you might want to mix liquid and Hogan, hence my fallback on custom delimiters.

vvo commented 9 years ago

So we need to do this right?