11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
17.28k stars 495 forks source link

Use shortcode in frontmatter permalink? #1419

Closed jasonday closed 4 months ago

jasonday commented 4 years ago

I have a shortcode {% returnSlug data.value %} that takes the value from the data and returns a slug (specific to how I do slugs in my headless CMS). I want to use the shortcode in the permalink like so: permalink: "standard/{% returnSlug data.value1 %}/criteria/{{ data.value2 }}/index.html"

Is that possible within nunjucks template frontmatter?

araphiel commented 4 years ago

Is it possible for you to pre-process value1 in your 11ty data file?

const examplePages = [
    {
        title: "Contact",
        category: "company",
        slug: "contact",
    }
]

const transform = string => `yay-${string}`

const transformedPages = examplePages.map(page => {
    page.category = transform(page.category)
    return page
})

module.exports = transformedPages
---
pagination:
    data: transformedPages
    size: 1
    alias: tp
    addAllPagesToCollections: true
permalink: "{{ tp.category }}/{{ tp.slug }}/"
---
you get `/yay-company/contact/index.html`
zachleat commented 4 months ago

Confirmed this works in the latest Eleventy! See test at https://github.com/11ty/eleventy/commit/a0337317f48af40fcc95769df0f0e960dde38831