K
K
Kote2017-11-02 22:58:06
HTML
Kote, 2017-11-02 22:58:06

Why doesn't the PUG mixin accept variables?

Mixin:

mixin img(name, ext, alt)
  img(srcset='img/#{name}.#{ext},img/#{name}@2x.#{ext} 1.5x,img/#{name}@2x.#{ext} 2x', src='img/#{name}.#{ext}', alt='!={alt}')

Insert
+img('sail','jpg', 'alt text')
Outlet
<img srcset="img/#{name}.#{ext},img/#{name}@2x.#{ext} 1.5x,img/#{name}@2x.#{ext} 2x" src="img/#{name}.#{ext}" alt="#{alt}">

That is, the parameters are not filled with values, but remain in their original form. I also tried peeing like !{}, but it didn't help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2017-11-02
@kotemedia

mixin img(name, ext, alt)
  img(srcset=`img/${name}.${ext},img/${name}@2x.${ext} 1.5x,img/${name}@2x.${ext} 2x', src='img/${name}.${ext}`, alt=`${alt}`)

+img('sail','jpg', 'alt text')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question