Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extra variables to be passed to the template #52

Closed
B-Prod opened this issue Apr 11, 2017 · 5 comments
Closed

Allow extra variables to be passed to the template #52

B-Prod opened this issue Apr 11, 2017 · 5 comments

Comments

@B-Prod
Copy link

B-Prod commented Apr 11, 2017

Use case: pass a random string to the mustache template, so we can create a font-face definition like:

  • icons.eot?f7jjdvlkflikheqoxbt9#iefix

This may be really needed when updating an existing font on a site using cache mechanism.

This can be very easily done, by adding 1 line when building the SCSS file from the template:

consolidate[config.engine](config.path, {
                                        glyphs: glyphMap,
                                        fontName: config.fontName,
                                        fontPath: config.fontPath,
                                        cssClass: config.cssClass,
                                        config: config
                                }, function(err, html) {

It just pass the full "config" variable, so if you add any extra variable in the Gulp file, it is available in the template.

Full example

Gulpfile

.pipe(iconfontCSS({
      fontName: fontName,
      path: './src/templates/iconfont/_icons.scss',
      targetPath: '../src/scss/abstractions/_font-icons.scss',
      fontPath: '../fonts/',
      cssClass: 'fonticon',
      hash: Math.random().toString(36).substring(6)
    }))

Template

@font-face {
  font-family: "<%= fontName %>";
  src: url('<%= fontPath %><%= fontName %>.eot?<%= config.hash %>');
  src: url('<%= fontPath %><%= fontName %>.eot?<%= config.hash %>#iefix') format('eot'),
    url('<%= fontPath %><%= fontName %>.woff2?<%= config.hash %>') format('woff2'),
    url('<%= fontPath %><%= fontName %>.woff?<%= config.hash %>') format('woff'),
    url('<%= fontPath %><%= fontName %>.ttf?<%= config.hash %>') format('truetype'),
    url('<%= fontPath %><%= fontName %>.svg?<%= config.hash %>#<%= fontName %>') format('svg');
}
@PengJiyuan
Copy link

Nice idea!

@Finesse
Copy link

Finesse commented Oct 12, 2017

Need it too

@gintsmurans
Copy link

gintsmurans commented Apr 10, 2018

Exactly what I was looking for.

For now solved an issue by putting extra code in template:

@font-face {
	font-family: "<%= fontName %>";
	<% var hash = Math.random().toString(36).substring(6) %>
	src: url('<%= fontPath %><%= fontName %>.eot?<%= hash %>');
	src: url('<%= fontPath %><%= fontName %>.eot?<%= hash %>#iefix') format('eot'),
		url('<%= fontPath %><%= fontName %>.woff2?<%= hash %>') format('woff2'),
		url('<%= fontPath %><%= fontName %>.woff?<%= hash %>') format('woff'),
		url('<%= fontPath %><%= fontName %>.ttf?<%= hash %>') format('truetype'),
		url('<%= fontPath %><%= fontName %>.svg?<%= hash %>#<%= fontName %>') format('svg');
}

@backflip
Copy link
Owner

@B-Prod, does the change in #42 solve your issue?

@B-Prod
Copy link
Author

B-Prod commented Jun 5, 2018 via email

@backflip backflip closed this as completed Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants