P
P
pleya2019-02-04 14:31:29
Pug
pleya, 2019-02-04 14:31:29

Why isn't the mixin working in Pug?

Good afternoon.

mixin section(props)
  -
    var allMods = '';
    if(typeof(props.mods) !== 'undefined' && props.mods) {
      var modsList = props.mods.split(',');
      for (var i = 0; i < modsList.length; i++) {
        allMods = allMods + ' section--' + modsList[i].trim();
      }
    }
  -
    if(typeof(props.bg) !== 'undefined' && props.mods) {
      section(class='section' + allMods style="background-image: url('https://source.unsplash.com/MYlCex1M7Ok/1920x200')")
        .container
          block
    }

  section(class='section' + allMods)
    .container
      block

I can't figure out what's wrong

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-02-04
@pleya

Incorrectly formatted second if. We fix:

mixin section(props)
  -
    var allMods = '';
    if (typeof(props.mods) !== 'undefined' && props.mods) {
      var modsList = props.mods.split(',');
      for (var i = 0; i < modsList.length; i++) {
        allMods = allMods + ' section--' + modsList[i].trim();
      }
    }

  if props.bg && props.mods
    section(class='section' + allMods style="background-image: url('https://source.unsplash.com/MYlCex1M7Ok/1920x200')")
      .container
        block

  section(class='section' + allMods)
    .container
      block

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question