A
A
Artem Zavalei2020-12-21 01:04:04
Pug
Artem Zavalei, 2020-12-21 01:04:04

Pug gives "Cannot read property 'length' of undefined" error, how to solve the problem?

There is an array on the main page:

-
  let catalogItems = [
    {
      'link': '#',
      'imgSrc': '123',
      'name': 'Hello”'
    },
    {
      'link': '#',
      'imgSrc': '123',
      'name': 'Hello”'
    },
  ]

I connect the module as an inclusion, in which there is a layout of the product catalog.
.catalog__inner
  h1.heading.page__heading= catalogTitle
  .grid__wrap
    each item in catalogItems
        .grid__item
          a(href=item.link).catalog__item-preview
            .catalog__item-img
              img(src="../img/"+ item.imgSrc +".jpg" alt=item.name)
              span.catalog__item-more Подробнее
            span.catalog__item-name #{item.name}

But for some reason, the pag displays the error "Cannot read property 'length'. If this array is moved to the module itself, there is no error and everything outputs fine. But it's super inconvenient. How to solve this problem in order to store all the information on the main page and just connect modules that are needed without pushing this information into them.

Ps this is an early stage, the product card will be taken out into a separate module with a mixin of this layout and connected to the module with the catalog.
Pss h1 outputs normally, defined on the main page, where I want to define this array.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question