Marcotss / parcel-transformer-handlebars-json

Handlebars plugin for Parcel 2 using json
MIT License
0 stars 0 forks source link

Content JSON not loaded #1

Open monsieurBelbo opened 1 year ago

monsieurBelbo commented 1 year ago

I am using the library to compile Handlebars templates and partials and it works as expected. However, it seems not to be loading my content JSON and its data is not available for the templates.

My handlebars.config.json has the following:

{
  "data": "src/data",
  "layouts": "src/layouts",
  "partials": "src/partials"
}

and its being loaded correctly since partials and layouts (not in the default location) are being compiled by the transformer.

This is my src/ directory structure:

src
├── data
│   └── content.json
├── layouts
│   └── base.hbs
├── pages
│   └── index.hbs
└── partials
    ├── sidebar.hbs
    ├── header.hbs
    ├── ...
    ├── ...
    └── ...

and the content of my src/data/content.json is:

{
  "title": "Control UI",
  "menu": [
    {
      "name": "Dashboard",
      "active": true,
      "icon": "HomeIcon",
      "url": "/"
    }
  ]
}

and this is the top of my src/pages/index.hbs:

{{!< base}}

<main class="h-full overflow-y-auto" x-init="fetchTankData">
    <div class="container px-6 mx-auto grid">
        <h2 class="my-6 text-2xl font-semibold text-gray-700 dark:text-gray-200">
            {{ title }}
        </h2>

No data seems to be loaded from the content JSON and available to my templates.

BeSublime commented 8 months ago

Hi there! Ran into this same issue, so if you're still wondering (or if anyone else comes across this), it seems the plugin puts the data into an object with the name of the json file, so for your example where the file is content.json it would be accessed via {{content.menu}}. (In my case, the file is called cards.json, so I access mine via {{cards.xyz}}.)

monsieurBelbo commented 7 months ago

That worked! Thank you