How can I access the html text in static resource file in lightning client-side controller?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite
1












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.










share|improve this question







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.

























    up vote
    3
    down vote

    favorite
    1












    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.










    share|improve this question







    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.





















      up vote
      3
      down vote

      favorite
      1









      up vote
      3
      down vote

      favorite
      1






      1





      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.










      share|improve this question







      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






      share|improve this question







      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.











      share|improve this question







      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.









      share|improve this question




      share|improve this question






      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.




















          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



          enter image description here






          share|improve this answer




















          • 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










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          hellohowdoyoudo is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          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






























          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



          enter image description here






          share|improve this answer




















          • 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














          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



          enter image description here






          share|improve this answer




















          • 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












          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



          enter image description here






          share|improve this answer












          <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



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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
















          • 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










          hellohowdoyoudo is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          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.













           


          draft saved


          draft discarded














          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













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          One-line joke