Skip to content

Multiple json-ld data in same page #245

@davideghz

Description

@davideghz

Honestly not sure whether this is a bug or an intended "missing feature"

Description / Use cases

I would like to generate multiple JSON-LD data for my pages.
In the same page I'd like to define json data for LocalBusiness, WebSite, Service, Organization / WebPage, ...

What I'm doing now

pass schemas to context and render in template, like:

views.py

...
business_info = {
    "@context": "https://schema.org",
    "@type": "LocalBusiness",
    "name": "My LocalBusiness Name"
    ...
}

website_info = {
    "@context": "https://schema.org",
    "@type": "Website",
    ...
}

service_info = {
    "@context": "https://schema.org",
    "@type": "Service",
    ...
}

context_data = {
  'meta': meta,
  'business_info': business_info,
  'website_info': website_info,
  'service_info': service_info
  ...
}
return render(request, "static_pages/home.html", context_data)

base.html

<head {% meta_namespaces %}>
    {% include 'meta/meta.html' %}
    {% if business_info %}
        <script type="application/ld+json">
            {{ business_info|json_script:"business_info" }}
        </script>
    {% endif %}
    {% if website_info %}
        <script type="application/ld+json">
            {{ website_info|json_script:"website_info" }}
        </script>
    {% endif %}
    {% if service_info %}
        <script type="application/ld+json">
            {{ service_info|json_script:"service_info" }}
        </script>
    {% endif %}
</head>

Proposed solution (currently not working)

It would be great to be able to to pass to meta context something like the following, and having django-meta managing the rendering in the template

all_schema = [
    business_info,
    website_info,
    service_info,
]

meta = Meta(
    request=request,
    title="My Page Title",
    description="My Page Description,
    schema=all_schema,
)

context_data = {
  'meta': meta,
  ...
}
return render(request, "static_pages/home.html", context_data)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions