Newer Version Available
Use Lightning Components in Visualforce Pages
- Add the <apex:includeLightning /> component to your Visualforce page.
- Reference a Lightning app that declares your component dependencies with $Lightning.use().
- Write a function that creates the component on the page with $Lightning.createComponent().
Adding <apex:includeLightning>
Add <apex:includeLightning /> at the beginning of your page. This component loads the JavaScript file used by Lightning Components for Visualforce.
Referencing a Lightning App
1<aura:application access="GLOBAL" extends="ltng:outApp">
2 <aura:dependency resource="ui:button"/>
3</aura:application>1$Lightning.use("theNamespace:lcvfTest", function() {});Creating a Component on a Page
Finally, create your component on a page using $Lightning.createComponent(String type, Object attributes, String locator, function callback). This function is similar to $A.createComponent(), but includes an additional parameter, domLocator, which specifies the DOM element where you want the component inserted.
1<apex:page>
2 <apex:includeLightning />
3
4 <div id="lightning" />
5
6 <script>
7 $Lightning.use("c:lcvfTest", function() {
8 $Lightning.createComponent("ui:button",
9 { label : "Press Me!" },
10 "lightning",
11 function(cmp) {
12 // do some stuff
13 });
14 });
15 </script>
16</apex:page>This code creates a DOM element with the ID “lightning”, which is then referenced in the $Lightning.createComponent() method. This method creates a ui:button that says “Press Me!”, and then executes the callback function.