Format Currency Data

I’m using Ghost 3.0 and trying to get member subscriptions setup on my blog, but I’m running into a problem with the subscription attributes.

Say I wanted to show a user how much they are paying every month/year, I would have something like this in my theme:

{{#foreach @member.subscriptions}}
  <p>You're currently paying ${{plan.amount}}/{{plan.interval}}. Your plan will renew on {{date current_period_end format="MMMM DD, YYYY"}}.</p>
{{/foreach}}

The {{plan.amount}} attribute is formatted to return the smallest currency denomination, i.e. if I make the monthly plan $5 it returns 500 (cents).

But Ghost doesn’t give me a data helper for formatting currency, so how am I to format the data I was given back to $5? (Arguably what it should have been anyways.)

Yeah at the moment this is a really ridiculous setup which we haven’t properly solved yet (sorry) – here’s how I make it work atm on Rediverge:

{{#if @member.paid}}

    {{!-- Logged in, paying member: Show account info --}}
    <article class="post-content">
        <div class="container">
            <div class="content">
                <form class="authbox">
                    <h1 class="authbox-title">Nice, you're a subscriber!</h1>
                    <p>Hey! <strong>{{@member.email}}</strong> has an active {{@site.title}} account with access to all areas. You're all set, but if you need any help, get in touch on <code>support@rediverge.com</code> for assistance!</p>
                    <div class="authbox-signup">
                        {{#foreach @member.subscriptions}}

                        <ul>
                            <li><strong>Plan:</strong> Early adopter — $<span class="plan-price">0</span>/{{plan.interval}}</li>
                            <li><strong>Card:</strong> **** **** **** {{default_payment_card_last4}}</li>
                            <li><strong>Renews:</strong> {{date current_period_end format="DD MMM YYYY"}}</li>
                        </ul>

                        {{#contentFor "scripts"}}
                        <script>
                            $(document).ready(function () {
                                var planAmount = {{plan.amount}} / 100;
                                $(".plan-price").html(planAmount);
                            });
                        </script>
                        {{/contentFor}}

                        {{/foreach}}
                    </div>
                </form>
            </div>
        </div>
    </article>

{{else if @member}}

We’ll have a proper helper for doing this correctly soon

5 Likes

Thanks for your help John, that will work for now.

I’ll be on the lookout for an update.