ActiveCampaign/mustachio

Show/display paragraph

Closed this issue · 2 comments

Hi guys,

I cant find a way to show/hide a paragraph base if a node exist or not.

My json is

{
  "organization": {
    "name": "name_Value",
    "id": "id_Value"
  },
  "credit": {
      "reason": "Promo code",
      "amount": "333"
  }
}

And part of the template

 <p>You have been invited to {{organization.name}}!  Click here to activate your account and to create your first project. {{#credit}}{{credit.reason}} credit of ${{credit.amount}} has been applied. {{/credit}} </p> 

What Im doing wrong?

Hi @mustela,

Here is the syntax you would want to use here:

You have been invited to {{organization.name}}! Click here to activate your account and to create your first project. {{#credit}}{{reason}} credit of ${{amount}} has been applied. {{/credit}}

When you use {{#credit}} you are automatically scoped to the credit object, so you can access its properties with just {{reason}} and {{amount}} (instead of credit.reason and credit.amount).

When you use a TemplateModel where "credit" is null or absent, nothing will be rendered. If either the reason or amount properties are present, that block will be shown.

Keep in mind that this would still render that block:

{
  "organization": {
    "name": "name_Value"
  },
  "credit": {
    "reason":null,
    "amount":null
  }
}

But this won't:

{
  "organization": {
    "name": "name_Value"
   },
   "credit": null
}

https://github.com/wildbit/mustachio/wiki/Where's-my-%60if%60-syntax%3F

I hope this helps clarify for you.

Oh thats great, thanks!