惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
M
MIT News - Artificial intelligence
D
Docker
S
SegmentFault 最新的问题
B
Blog
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
C
Check Point Blog
GbyAI
GbyAI
美团技术团队
Recent Announcements
Recent Announcements
F
Fortinet All Blogs
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog

Example blog

Ghost routing explained with routes.yaml examples — routes, collections & taxonomies Ghost redirects explained with practical redirects.yaml examples How to Serve JSON or XML Data in Ghost How to Change Your Default Post Template in Ghost Ghost Custom Theme Settings How to add Google Fonts to Ghost Themes How to Configure Ghost with Mailgun Ghost Theme Structure & Organization How to Make Custom Templates in Ghost Themes How to Install Ghost CMS via Ghost-CLI How to Add Syntax Highlighting to Ghost The best Ghost CMS hosting platforms Ghost 6.0 — Social Web and Native Ghost Analytics Ghost CMS Social web beta, email 2FA and more author social links How to keep custom design settings when updating your Ghost theme How to use the public preview card in Ghost How to add members-specific sections in Ghost How to customize the default content CTA in Ghost How to build a custom homepage in Ghost An overview of Ghost editor cards and and how they work Ghost CMS News: One-time payments & collecting sales tax How to customize the private site access template in Ghost How to add custom fonts in Ghost themes Ghost CMS News: Additional payment methods & internal linking How to use Code Injection in Ghost How to set meta data of your custom routes & collections in Ghost Ghost CMS News: TK reminders, ActivityPub and improvements How to format dates and use the date helper in Ghost Ghost CMS internationalization, custom fonts & spam protection Understanding and optimizing post and page settings in Ghost CMS
Ghost CMS Price Helper Overview & Tips
Bright Themes · 2022-12-20 · via Example blog

The price helper is a function in Ghost that allows you to display prices on your website in a consistent and user-friendly format. Ghost handles this automatically in Portal, but if you have a custom membership page, or another place to show your membership plans or tiers then you have to use the {{price}} helper.

Price helper options

The Ghost price helper comes with a number of options that you can use to customize the display of prices. Here are the options available:

  • amount - the amount option allows you to specify the numerical value of the price. This value can be an integer or a decimal number, depending on the level of precision required.
  • currency - the currency option allows you to specify the currency in which the price will be displayed. You can use the three-letter ISO currency code to specify the currency, such as "USD" for US dollars or "EUR" for Euros.
  • locale - the locale options allows you to change format of the price, based on the language, the default is "@site.locale"
  • numberFormat - the numberFormat option allows you to define the price precision. You can use "short" or "long", with "short" being the default value.
  • currencyFormat - the currencyFormat option allows you to specify the currency format for the price. This can be either "symbol" or "code", "symbol" being the default value.

By using these options, you can customize the display of prices on your Ghost website to suit your needs and preferences. You can also use these options in combination with each other to achieve the desired display format for your prices.

Now let's see some examples with specific use cases.

Price helper use case & examples

Basic usage:

{{price plan}}

This will display a members price plan. Here's the more advanced usage of the helper:

{{price
  plan.amount
  currency=plan.currency
  locale=@site.locale
  numberFormat='short'
  currencyFormat='symbol'
}}

Now let's seem some more specific use cases for the price helper.

  1. Display a members subscription plan:
{{#foreach @member.subscriptions}}
  {{price plan}}/{{plan.interval}}
  <!-- Outputs: $99/year -->
{{/foreach}}

For this to work, you have to be in the right context, in this case it's @member.subscriptions.

  1. Display a membership tier monthly or yearly price:
{{#get 'tiers' include='monthly_price,yearly_price,benefits'}}
  {{#foreach tiers}}
    {{price monthly_price currency=currency}}
    <!-- Outputs: $9/month -->
  {{/foreach}}
{{/get}}
{{#get 'tiers' include='monthly_price,yearly_price,benefits'}}
  {{#foreach tiers}}
    {{price yearly_price currency=currency}}
    <!-- Outputs: $99/year -->
  {{/foreach}}
{{/get}}

In both cases you have to be in the right context, which in this case is the tiers object.

  1. Display a static price:
{{price 0 currency='USD'}}
<!-- Outputs: $0 -->

Conclusions

Overall, the Ghost price helper is a useful tool for displaying prices on your website in a consistent and user-friendly format. By using the options and customization features available in the price helper, you can tailor the display of prices to suit your business needs and preferences.