Unable to use Font Awesome Icons inside of the Canvas
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 CS...
Read full answer below ↓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)
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.
Issue #1162
[Question]: Editable components in Handlebars rendered template
Hi, I've been using grapes for about a couple of days now. Thanks for the awesome work on this project. I've read through the API docs (hop...
Issue #2065
Few Questions
First of all, Amazing project thumbs up to everybody involved. I have a couple of questions:How can I iterate over all of the components an...
Issue #3287
Wrapper styling
First of all, congrats @artf for this amazing project 💯 I am currently working on a project and I wanted to ask if I can edit the wrapper...
Issue #3345
Panels and Buttons section of getting started not working with Vue.js
I am working to get grapejs to work with Vue.js and am having no luck, I am following the getting started however I am unable to get it to...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.