[SalesForce] How to call html content stored in static resource in lightning component

I have a requirement where I need to store all the footer content(.html files) in static resource and use that in lightning component.
I didn't find any documents where we can use the html content stored in static resource in lightning component.

Best Answer

You've got two routes to get access to Static Resources from a Lightning component. This is really not a workflow that Salesforce strongly supports; a much more idiomatic place to store HTML as is as part of the markup of a child Lightning component.

One route is to use the <ltng:require> component. This asynchronously loads your resource as a JavaScript file. If that file contains a global assignment, you'll be able to access it in your Lightning component's JavaScript. That resource content could be JavaScript that dynamically creates HTML elements, or it could be escaped HTML content that your client-side JavaScript can dynamically insert into your own component's DOM

The other route is to make a server call to your Apex controller, which can query and return raw HTML content (not JavaScript) from the static resource. e.g.

@AuraEnabled
public static String getHTMLContent(String staticResourceName) {
     return [SELECT Body FROM StaticResource WHERE Name = :staticResourceName].Body;
}