嗨,有人知道如何在Pug中使用href吗?
我想实现的是这样:
<noscript class="lazyload">
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/style.css">
</noscript>
我尝试了这个,但是没有用。
noscript.lazyload
link(rel='stylesheet', href!="<? php echo get_template_directory_uri(); ?>/style.css ")
这是我的gulpfile.babel.js配置:
import pug from 'gulp-pug'
import rename from 'gulp-rename'
import pugPHPFilter from 'pug-php-filter'
gulp.task('pug', () => {
let option = {
pretty: true,
filters: {
php: pugPHPFilter
}
}
return gulp.src('./pug/*.pug')
.pipe(pug(option))
.pipe(rename({
extname: '.php'
}))
.pipe(plumber())
.pipe(gulp.dest('./'));
});
答案 0 :(得分:0)
我将您的html转换为pug usign https://html2jade.org/,结果如下:
noscript.lazyload
link(rel='stylesheet', href='<?php echo get_template_directory_uri(); ?>/style.css')
尝试将PHP分配给Javascript变量:
noscript.lazyload
-var template_uri = <?php echo get_template_directory_uri(); ?>
link(rel='stylesheet', href=template_uri+'/style.css')