Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

149
Vistas
How do I use JS String Interpolation to insert Shopify sections? ('not a valid section type')

I'm building a 'view' template for certain blogs' tags. I'm grabbing the pathname with javascript and trying to insert a hero section based on which tag the user is on. If I hardcode the blog name and tag into the section string, it works. But if I try to interpolate the variables into it, I get a liquid error.

The code:

const pathName = window.location.pathname;
let blog_div = document.getElementById('blog-hero');
let blogName = pathName.split('/')[2];
let tagName = pathName.split('/')[4];

return blog_div.innerHTML = `{% section 'blog--hero-${blogName}-blog--${tagName}' %}`;

Expected Output: Section loads on screen

Actual Output: Nothing on-screen. Error in HTML: 'Liquid error: Error in tag 'section' - 'blog--hero-(blogName)-blog--(tagName)' is not a valid section type'

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Ended up using the Section Rendering API, per the docs.

But the JSON.parse() line didn't work. So I had to use the onload, readyState, and status methods per the MDN docs

New code ended up looking like

const pathName = window.location.pathname;
let blog_div = document.getElementById('blog-hero');
let blogName = pathName.split('/')[2];
let tagName = pathName.split('/')[4];

let request = new XMLHttpRequest();
request.open('GET', `/?section_id=blog--hero-${blogName}-blog--${tagName}`)
request.onload = () => {
    if(request.readyState === request.DONE) {
        if (request.status === 200) {
            blog_div.innerHTML = request.responseText;
        }
    }
};

request.send(null);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda