S
S
SwaG2018-06-26 22:08:42
css
SwaG, 2018-06-26 22:08:42

How in Pug to shove a span into a string that is the value of an object?

How to write correctly in this case, so that in the end in HTML it turns out like this?:

<div class="block__title">second<span class="accent">title</span></div>

PS I store the text of identical elements in objects in an array, which I then substitute into the mixin parameters. Am I doing it right or is there a better way to do this?
- 
 var obj = [
    {title: 'first title', text: 'first text'},
    {title: 'second #[span.accent title]', text: 'second text'},
    {title: 'third title', text: 'third text'}
  ]
mixin features(title, text)
  .block
    .block__item
      img.block__img(src="/img/block/1.jpg")
      .block__title= title
      p.block__capture= text
each val, index in obj
  +features(val.title, val.text)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2018-06-26
@SwaG

In general, you can write html directly in values, and to output unescaped code, write !=

- 
 var obj = [
    {title: 'first title', text: 'first text'},
    {title: 'second <span class="accent">title</span> ', text: 'second text'},
    {title: 'third title', text: 'third text'}
  ]
mixin features(title, text)
  .block
    .block__item
      img.block__img(src="/img/block/1.jpg")
      .block__title!= title
      p.block__capture= text
each val, index in obj
  +features(val.title, val.text)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question