Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

230
Visualizações
How to get page title in config file in Eleventy JS?

I need to insert the title of the page in the ALT attribute. How to get the title? The code below is located in the .eleventy.js file

Right now I get the title if I pass in the props "title". But how to get the header without passing the props?

eleventyConfig.addShortcode('image', (src, className, title) => {
let classNameValue = (className) ? className : ' '
let titleValue = (title) ? title : ' '

    let cloudinary =
      'https://res.cloudinary.com/dr24pbwrs/image/upload/q_auto,f_auto/'
    let pathimg = src.replace(
      new RegExp('https://res.cloudinary.com/.*/image/upload/', 'g'),
      ''
    )

    return `<picture class="${classNameValue}">
                            <source
                                srcset="${cloudinary}w_768/${pathimg} 768w,
                                ${cloudinary}w_1024/${pathimg} 1024w,
                                ${cloudinary}w_1024/${pathimg} 1240w"
                                sizes="(min-width: 320px) 768px,
                                (min-width: 768px) 1024px,
                                (min-width: 1024px) 1240px,
                                100vw">
                            <img src="${cloudinary}${pathimg}" alt="${titleValue}" loading="lazy" />
                        </picture>`
  })
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Ok, so you want to use a regular function, not fat arrow, and that gives you access to the page object, but, you do not get access to the front matter. However, you know where the file is now and can use gray-matter to read it in. This answer explains how to do it.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda