How can I access the html text in static resource file in lightning client-side controller?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
3
down vote
favorite
How can I access the html text in static resource file in lightning client-side controller?
I know how to upload .html
file to static resources and how to acquire it using <ltng:require>
, but I do not know how to access its content once it is acquired.
html static-resources
New contributor
hellohowdoyoudo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
3
down vote
favorite
How can I access the html text in static resource file in lightning client-side controller?
I know how to upload .html
file to static resources and how to acquire it using <ltng:require>
, but I do not know how to access its content once it is acquired.
html static-resources
New contributor
hellohowdoyoudo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
How can I access the html text in static resource file in lightning client-side controller?
I know how to upload .html
file to static resources and how to acquire it using <ltng:require>
, but I do not know how to access its content once it is acquired.
html static-resources
New contributor
hellohowdoyoudo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
How can I access the html text in static resource file in lightning client-side controller?
I know how to upload .html
file to static resources and how to acquire it using <ltng:require>
, but I do not know how to access its content once it is acquired.
html static-resources
html static-resources
New contributor
hellohowdoyoudo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
hellohowdoyoudo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
hellohowdoyoudo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Sep 9 at 16:06
hellohowdoyoudo
654
654
New contributor
hellohowdoyoudo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
hellohowdoyoudo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
hellohowdoyoudo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
<ltng:require>
is used for loading JavaScript and style sheets, not static HTML. In order to make HTML content available for your Lightning JavaScript controller, you'd need to structure your static resource as a JavaScript file that assigns HTML content to some top-level property, which you can then access in your controller and include in your component.
Alternately, you'd need to call out to your server-side Apex controller to query for the body of the StaticResource
and return the data to you.
Here's an example of the former approach.
Static Resource testsr
window.myHTML = '<strong>Hello, <em>world!</em></strong>';
TestQ231776.app
<aura:application >
<aura:attribute type="String" name="html" />
<ltng:require scripts="! $Resource.testsr " afterScriptsLoaded="!c.afterScriptsLoaded" />
<p>
<aura:unescapedHtml value="! v.html " />
</p>
</aura:application>
TestQ231776Controller.js
(
afterScriptsLoaded : function(component, event, helper)
component.set('v.html', window.myHTML);
)
TestQ231776.css
.THIS strong
font-weight: bold;
.THIS em
font-style: italic;
Result
Oh. It is a pity that it is impossible to have an.html
file in static resources. So,.html
templates are impossible in lightning.
– hellohowdoyoudo
Sep 9 at 16:41
Well, that's overstating it a little. There are (at least) two routes to access static HTML, as above. But remember also that a Lightning component is itself something like a template. Your Lightning component markup is HTML + Lightning components.
– David Reed
Sep 9 at 17:06
Ok, got it. Thank you.
– hellohowdoyoudo
Sep 9 at 17:07
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
<ltng:require>
is used for loading JavaScript and style sheets, not static HTML. In order to make HTML content available for your Lightning JavaScript controller, you'd need to structure your static resource as a JavaScript file that assigns HTML content to some top-level property, which you can then access in your controller and include in your component.
Alternately, you'd need to call out to your server-side Apex controller to query for the body of the StaticResource
and return the data to you.
Here's an example of the former approach.
Static Resource testsr
window.myHTML = '<strong>Hello, <em>world!</em></strong>';
TestQ231776.app
<aura:application >
<aura:attribute type="String" name="html" />
<ltng:require scripts="! $Resource.testsr " afterScriptsLoaded="!c.afterScriptsLoaded" />
<p>
<aura:unescapedHtml value="! v.html " />
</p>
</aura:application>
TestQ231776Controller.js
(
afterScriptsLoaded : function(component, event, helper)
component.set('v.html', window.myHTML);
)
TestQ231776.css
.THIS strong
font-weight: bold;
.THIS em
font-style: italic;
Result
Oh. It is a pity that it is impossible to have an.html
file in static resources. So,.html
templates are impossible in lightning.
– hellohowdoyoudo
Sep 9 at 16:41
Well, that's overstating it a little. There are (at least) two routes to access static HTML, as above. But remember also that a Lightning component is itself something like a template. Your Lightning component markup is HTML + Lightning components.
– David Reed
Sep 9 at 17:06
Ok, got it. Thank you.
– hellohowdoyoudo
Sep 9 at 17:07
add a comment |Â
up vote
3
down vote
accepted
<ltng:require>
is used for loading JavaScript and style sheets, not static HTML. In order to make HTML content available for your Lightning JavaScript controller, you'd need to structure your static resource as a JavaScript file that assigns HTML content to some top-level property, which you can then access in your controller and include in your component.
Alternately, you'd need to call out to your server-side Apex controller to query for the body of the StaticResource
and return the data to you.
Here's an example of the former approach.
Static Resource testsr
window.myHTML = '<strong>Hello, <em>world!</em></strong>';
TestQ231776.app
<aura:application >
<aura:attribute type="String" name="html" />
<ltng:require scripts="! $Resource.testsr " afterScriptsLoaded="!c.afterScriptsLoaded" />
<p>
<aura:unescapedHtml value="! v.html " />
</p>
</aura:application>
TestQ231776Controller.js
(
afterScriptsLoaded : function(component, event, helper)
component.set('v.html', window.myHTML);
)
TestQ231776.css
.THIS strong
font-weight: bold;
.THIS em
font-style: italic;
Result
Oh. It is a pity that it is impossible to have an.html
file in static resources. So,.html
templates are impossible in lightning.
– hellohowdoyoudo
Sep 9 at 16:41
Well, that's overstating it a little. There are (at least) two routes to access static HTML, as above. But remember also that a Lightning component is itself something like a template. Your Lightning component markup is HTML + Lightning components.
– David Reed
Sep 9 at 17:06
Ok, got it. Thank you.
– hellohowdoyoudo
Sep 9 at 17:07
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
<ltng:require>
is used for loading JavaScript and style sheets, not static HTML. In order to make HTML content available for your Lightning JavaScript controller, you'd need to structure your static resource as a JavaScript file that assigns HTML content to some top-level property, which you can then access in your controller and include in your component.
Alternately, you'd need to call out to your server-side Apex controller to query for the body of the StaticResource
and return the data to you.
Here's an example of the former approach.
Static Resource testsr
window.myHTML = '<strong>Hello, <em>world!</em></strong>';
TestQ231776.app
<aura:application >
<aura:attribute type="String" name="html" />
<ltng:require scripts="! $Resource.testsr " afterScriptsLoaded="!c.afterScriptsLoaded" />
<p>
<aura:unescapedHtml value="! v.html " />
</p>
</aura:application>
TestQ231776Controller.js
(
afterScriptsLoaded : function(component, event, helper)
component.set('v.html', window.myHTML);
)
TestQ231776.css
.THIS strong
font-weight: bold;
.THIS em
font-style: italic;
Result
<ltng:require>
is used for loading JavaScript and style sheets, not static HTML. In order to make HTML content available for your Lightning JavaScript controller, you'd need to structure your static resource as a JavaScript file that assigns HTML content to some top-level property, which you can then access in your controller and include in your component.
Alternately, you'd need to call out to your server-side Apex controller to query for the body of the StaticResource
and return the data to you.
Here's an example of the former approach.
Static Resource testsr
window.myHTML = '<strong>Hello, <em>world!</em></strong>';
TestQ231776.app
<aura:application >
<aura:attribute type="String" name="html" />
<ltng:require scripts="! $Resource.testsr " afterScriptsLoaded="!c.afterScriptsLoaded" />
<p>
<aura:unescapedHtml value="! v.html " />
</p>
</aura:application>
TestQ231776Controller.js
(
afterScriptsLoaded : function(component, event, helper)
component.set('v.html', window.myHTML);
)
TestQ231776.css
.THIS strong
font-weight: bold;
.THIS em
font-style: italic;
Result
answered Sep 9 at 16:36


David Reed
19.7k21540
19.7k21540
Oh. It is a pity that it is impossible to have an.html
file in static resources. So,.html
templates are impossible in lightning.
– hellohowdoyoudo
Sep 9 at 16:41
Well, that's overstating it a little. There are (at least) two routes to access static HTML, as above. But remember also that a Lightning component is itself something like a template. Your Lightning component markup is HTML + Lightning components.
– David Reed
Sep 9 at 17:06
Ok, got it. Thank you.
– hellohowdoyoudo
Sep 9 at 17:07
add a comment |Â
Oh. It is a pity that it is impossible to have an.html
file in static resources. So,.html
templates are impossible in lightning.
– hellohowdoyoudo
Sep 9 at 16:41
Well, that's overstating it a little. There are (at least) two routes to access static HTML, as above. But remember also that a Lightning component is itself something like a template. Your Lightning component markup is HTML + Lightning components.
– David Reed
Sep 9 at 17:06
Ok, got it. Thank you.
– hellohowdoyoudo
Sep 9 at 17:07
Oh. It is a pity that it is impossible to have an
.html
file in static resources. So, .html
templates are impossible in lightning.– hellohowdoyoudo
Sep 9 at 16:41
Oh. It is a pity that it is impossible to have an
.html
file in static resources. So, .html
templates are impossible in lightning.– hellohowdoyoudo
Sep 9 at 16:41
Well, that's overstating it a little. There are (at least) two routes to access static HTML, as above. But remember also that a Lightning component is itself something like a template. Your Lightning component markup is HTML + Lightning components.
– David Reed
Sep 9 at 17:06
Well, that's overstating it a little. There are (at least) two routes to access static HTML, as above. But remember also that a Lightning component is itself something like a template. Your Lightning component markup is HTML + Lightning components.
– David Reed
Sep 9 at 17:06
Ok, got it. Thank you.
– hellohowdoyoudo
Sep 9 at 17:07
Ok, got it. Thank you.
– hellohowdoyoudo
Sep 9 at 17:07
add a comment |Â
hellohowdoyoudo is a new contributor. Be nice, and check out our Code of Conduct.
hellohowdoyoudo is a new contributor. Be nice, and check out our Code of Conduct.
hellohowdoyoudo is a new contributor. Be nice, and check out our Code of Conduct.
hellohowdoyoudo is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f231776%2fhow-can-i-access-the-html-text-in-static-resource-file-in-lightning-client-side%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password