Make Custom Handlebar Helpers in Ghost!

This page summarizes the projects mentioned and recommended in the original post on dev.to

Civic Auth - Auth in Less Than 5 Minutes
Civic Auth comes with multiple SSO options, optional embedded wallets, and user management — all implemented with just a few lines of code. Start building today.
www.civic.com
featured
InfluxDB high-performance time series database
Collect, organize, and act on massive volumes of high-resolution data to power real-time intelligent systems.
influxdata.com
featured
  1. express-http-proxy

    Proxy middleware for express/connect

    The middleware is an Express server running in Node.js with the added express-http-proxy (https://github.com/villadora/express-http-proxy) library, which significantly simplifies the work. We configure the proxy to communicate with the Ghost instance. The express-http-proxy library has a userResDecorator property that we can use to "decorate the response of the proxied server." Simply put, we can modify the response from Ghost before sending it to the user's browser.

  2. Civic Auth

    Auth in Less Than 5 Minutes. Civic Auth comes with multiple SSO options, optional embedded wallets, and user management — all implemented with just a few lines of code. Start building today.

    Civic Auth logo
  3. Knex

    A query builder for PostgreSQL, MySQL, CockroachDB, SQL Server, SQLite3 and Oracle, designed to be flexible, portable, and fun to use.

    If you want to make database queries in Ghost to fetch, for example, the current post, it’s possible and not difficult. You can use a library like knex (https://knexjs.org/), which is a clear and fast SQL query builder. Remember that you’ll need handlebars-async-helpers for this. Configure knex properly to connect to Ghost’s database.

  4. handlebars.js

    Minimal templating on steroids.

    In this variable, we have the response from the Ghost instance as the full HTML of the page. Imagine that this response is the homepage of your Ghost instance. The HTML content will also include our plain text {{hello_world}}, which is displayed as plain text. If our custom helper is in this form, we can compile it using Handlebars.js (https://handlebarsjs.com/) in our middleware. Remember to install the library first via a package manager, e.g., npm: npm install handlebars and add it to your code: const handlebars = require("handlebars");.

  5. cheerio

    The fast, flexible, and elegant library for parsing and manipulating HTML and XML.

    Another thing! Imagine a user adds such a helper in the comments section under a post and adds malicious content in the parameter. Be mindful of security. For example, if you render every HTML completely, you could be vulnerable to XSS attacks. It’s recommended to compile and render Handlebars.js in specific, closed areas. You can use the cheerio (https://cheerio.js.org/) library for parsing HTML and rendering Handlebars where necessary. Here’s an example of how you can secure yourself by modifying the previous rendering code:

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Configure TLS in Redis Cluster

    1 project | dev.to | 9 Apr 2025
  • Setup a Redis Cluster using Redis Stack

    1 project | dev.to | 26 Mar 2025
  • Debugging Complex SQL Queries: A Structured Logging Approach

    3 projects | dev.to | 4 Mar 2025
  • Redis 8.0-M3 Brings Async I/O Threading, 12x Speed-Up with New AVX2 Code Path

    1 project | news.ycombinator.com | 28 Feb 2025
  • How to Increase API Performance

    2 projects | dev.to | 18 Feb 2025

Did you know that JavaScript is
the 3rd most popular programming language
based on number of references?