Issue #2481Opened December 30, 2019by andrewryan19061 reactions

Unable to use Font Awesome Icons inside of the Canvas

Question

First off, great work on an amazing project. Can't believe this exists.

OK, I've spent the last few days going through the docs and now am starting to build my own components. However; for template design, I want my components to render differently. I can see that I can intercept the rendering and change that.

But I'm trying to render this:

<div class="templateComponent"> <i class="fa fa-utensils-alt"></i></i> Advanced Menu</div>

And for some some reason, this Font Awesome icon will NOT render. This same icon works fine when rendering blocks like this:

  attributes: {class: 'fas fa-utensils-alt fa-2x'},

I then discovered that no Font Awesome icons render inside of the canvas. Why?

Answers (1)

andrewryan1906December 30, 20191 reactions

I actually discovered the problem halfway through writing the post but decided to finish it and leave it here in case anyone ran into this.

The styles used for panels, blocks, etc don't apply to the styles inside of the canvas, since the canvas is in an iframe. The problem was that I hadn't installed Font Awesome's CSS inside of the canvas (but had in my outer application, which is why it was working for blocks).

You can do this in the init:

 grapesjs.init({
  .. // other stuf
    canvas: {
          // any  style sheets here are imported and used for the canvas ONLY
            styles: [
              "https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
            ]
   },
 
 // and anything inside the baseCSS is included in a <styles> tag inside the canvas, 
 // allowing you to specify inline styles
  baseCss: ` random CSS styles`
}

Also - if you want to change the appearance of items inside of the canvas, you can include inline styles using the baseCSS property.

Thanks, Andrew

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.