# How add different JSON-LD per layout

**URL:** <https://discourse.gohugo.io/t/how-add-different-json-ld-per-layout/54685>\
**Category:** support\
**Created:** [May 9, 2025, 8:54am UTC](https://discourse.gohugo.io/t/how-add-different-json-ld-per-layout/54685 "2025-05-09T08:54:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jswtch](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jswtch/32/8984_2.png) [@jswtch](https://discourse.gohugo.io/u/jswtch)\
**Post date:** [May 9, 2025, 8:54am UTC](https://discourse.gohugo.io/t/how-add-different-json-ld-per-layout/54685/1 "2025-05-09T08:54:51Z")

</div>

Hello I am trying to add JSON-LD schema to each page in sections: [events](https://schema.org/Event), [services](https://schema.org/Service), and [blog](https://schema.org/Blog)

Each of those sections is a branch bundle on my site. I am wondering what might be a good way to implement the structured data for each page within each section.

```sh
├── content
│ ├── events
│ ├── services
│ ├── blog

```

Is there a way to store the schema as a branch bundle resource and populate it on render? Should I have one conditional in the baseof based on section? Are you just storing structure as a string and populating with printf then safeHTML? Also I am curious about your use of blocks vs partials?

I am curious to know how you are handling structure data.

---

<div class="post-metadata">

**Author:** ![ju52](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ju52/32/6749_2.png) [@ju52](https://discourse.gohugo.io/u/ju52)\
**Post date:** [May 9, 2025, 9:36am UTC](https://discourse.gohugo.io/t/how-add-different-json-ld-per-layout/54685/2 "2025-05-09T09:36:39Z")

</div>

I have a JSON feed on my sample site ( and RSS and ATOM)  
[GitHub - gj52/HugoSample: Hugo Sample](https://github.com/gj52/HugoSample)  
Should be easy to copy, search for JSON

---

<div class="post-metadata">

**Author:** ![davidsneighbour](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/davidsneighbour/32/24507_2.png) [@davidsneighbour](https://discourse.gohugo.io/u/davidsneighbour)\
**Post date:** [May 9, 2025, 10:08am UTC](https://discourse.gohugo.io/t/how-add-different-json-ld-per-layout/54685/3 "2025-05-09T10:08:40Z")

</div>

> [@jswtch](#):
>
> ```auto
> ├── content
> │ ├── events
> │ ├── services
> │ ├── blog
> 
> ```

Events is a `section`, services is a `section`. So you can filter by `.Section` when you range over the page object and then create based on that the JSON markup from the page object.

Basically, at the end of your `<article>` tag (I think you might have that if you are using other standards like json-ld too) add a partial like this:

```auto
{{ partialCached "schema.html" . . }} 

```

This will cache the output once per page (second .) and receive the page as context (first .). Then in `layouts/partials/schema.html` you do a check which section you are in and create your schema:

```auto
{{ if eq .Section "events" }}
.... events schema
{{ else if eq .Section "services" }}
... services schema
{{ else }}
.. all others
{{ end }}

```

You might have templates per section, in that case you don’t need to check for the section, just add in a partial. I would keep it out of baseof template and put it into a partial.

Also, work with a `dict` in your partial and then at the end transform into json via jsonify - that saves some encoding troubles.

I have some rudimentary schema partials [here](https://github.com/davidsneighbour/kollitsch.dev/tree/main/layouts/partials/schema/things) for inspiration. Check the end - jsonify, then safe.JS. That way your output looks good and nothing is scrambled.

---

<div class="post-metadata">

**Author:** ![jswtch](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jswtch/32/8984_2.png) [@jswtch](https://discourse.gohugo.io/u/jswtch)\
**Post date:** [May 10, 2025, 7:05am UTC](https://discourse.gohugo.io/t/how-add-different-json-ld-per-layout/54685/4 "2025-05-10T07:05:41Z")

</div>

Thank you @ju52 I will check it out!

---

<div class="post-metadata">

**Author:** ![jswtch](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jswtch/32/8984_2.png) [@jswtch](https://discourse.gohugo.io/u/jswtch)\
**Post date:** [May 10, 2025, 7:05am UTC](https://discourse.gohugo.io/t/how-add-different-json-ld-per-layout/54685/5 "2025-05-10T07:05:58Z")

</div>

Thank you @davidsneighbour I will check it out!
