11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.

Home Page:https://www.11ty.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eleventyComputed data key from pagination is empty/not set when same key is set in Directory Data File

Gr0t3Man opened this issue · comments

Operating system

Pop!_OS 22.04

Eleventy

v2.0.0

Describe the bug

When a key is defined in a directory data file (same or higher level directory) it prevents from setting the same key in a pagination file through eleventyComputed process. The key’s value is cleared during the process and not set by the new value.

Reproduction steps

Content of the directory data file /src/en/en.json

{
"language": "EN",
"translatedLanguage": "NL",
"translatedUrl": "/",
"homeUrl": "/en/",
"ogimage": "og-fb/robin-uitgaansmode-og-en-wide.jpg",
"locale": "en",
"layout": "layouts/default.njk",
"headMarge": "mt-2"
}

Content of the pagination file /src/en/products/products.njk

_

pagination:
data: catalog.page_info
size: 1
alias: true_name
addAllPagesToCollections: true
permalink: "/en/products/{{ true_name | slug }}.html"
tags: productmodel_en

eleventyComputed:
title: "{{ catalog.products[catalog.page_info[true_name].model]['title-eng'] }}"
description: "{{ catalog.products[catalog.page_info[true_name].model]['description-eng'] | excerpt }}"
descriptionFull: "{{ catalog.products[catalog.page_info[true_name].model]['description-eng'] }}"
ogimage: "og-col/robin-uitgaansmode-og-{{ catalog.page_info[true_name].model }}.jpg"
canonicallink: "/en/products/{{ catalog.page_info[true_name].model | slug }}.html"
translatedUrl: "/products/{{ true_name | slug }}.html"
mainLanguageUrl: "/products/{{ true_name | slug }}.html"

_

  1. Start Eleventy with eleventy --serve 
    
  2. The keys ‘ogimage’ and ‘transletedUrl’ are empty on output
    

Expected behavior

The keys generated by the computedData are expected to be set by the correct value’s.
Like a key which is set in the Config Global Data, by eleventyConfig.addGlobalData("translatedUrl", "/en/"); the key’s value is sets during the eleventyComputed process.

Temporarily Workaround

A workaround is a available by changing the keys-name in the pagination file. And calling the new key-names or overwriting the (directory data) keys with the new value’s in the template scripts.
For example:
_eleventyComputed:

ogimages: "og-col/robin-uitgaansmode-og-{{ catalog.page_info[true_name].model }}.jpg"
translateUrl: "/products/{{ true_name | slug }}.html"_

Calling the new ogimages

> meta property="og:image" content="{{ site.url }}{% imageLink ogimages or ogimage or site.ogimage.image %}"

Overwriting the value in (nunjucks file)

{% set translatedUrl = translateUrl %}

Reproduction URL

No response

Screenshots

No response