Introduction
PnP-JS-Core library contains a number of extensible methods and properties. By using that we can achieve the various actions in a simple code. To know more about this library component, visit the below links,
PnP-JS-Core Library
SharePoint has a lot of building blocks in collections which are used to form a SharePoint site. Those are used to manage the contents, generate reports based on contents and settings, etc…
Syntax
pnp.sp.site.rootweb – Gets the root web of the site collection
Example
The below steps and code snippet are used to return the root web object and properties from the current site collection.
- Download Required files to use PnP-JS-Core library from the below links and upload that to Site Assets or Style Library,
- Download pnp.js PnP JS file.
- Download fetch.js Used by PnP js file to handle web requests and responses (Required in IE)
- Download promise.js Used by PnP js file to handle web requests and responses (Required in IE)
- Download pnp.js PnP JS file.
- Create new web part page and insert Content Editor web part.
- Create a sample.html file in Site Assets or Style library and insert the below code snippet.
- <!-- Required JS file -->
- <script type="text/javascript" src="/siteassets/scripts/fetch.js"></script>
- <script type="text/javascript" src="/siteassets/scripts/promise.min.js"></script>
- <script type="text/javascript" src="/siteassets/scripts/pnp.min.js"></script>
- <div id="sample"></div>
- <script type="text/javascript">
- //The below PnP property used to return the root website of the site collection
- $pnp.sp.site.rootWeb.get().then(function(web) {
- document.getElementById("sample").innerText = "Title: " + web.Title + "\r\n" + "Description: " + web.Description;
- }).catch(function(err) {
- alert(err);
- });
- </script>
- Add the URL of sample.html file to the content editor webpart.
- Click ok to apply the changes to the webpart and save the page.
- Now the page displays the title and description of the root website.
Output

Conclusion
PnP-JS-Core library has a lot of simple extension properties and methods that help increases the performance and reduce the number of lines for code.


Vipin TyagiPosted Jul 6, 2016, 1:23 AM EDT
Thanks Shantha Kumar T Sir
kalu singh raoPosted Jul 1, 2016, 3:45 AM EDT
Nice...
Vipin TyagiPosted Jul 1, 2016, 2:39 AM EDT
Is there any official document to learn some basics to advance in PnP
Vipin TyagiPosted Jul 1, 2016, 2:38 AM EDT
Thanks ,But I'm using try catch and Sir It is not working in Mozilla Developer edition but fine with chrome and IE.
Vipin TyagiPosted Jun 30, 2016, 10:47 PM EDT
Need Your help Sir!
Vipin TyagiPosted Jun 30, 2016, 10:47 PM EDT
Finished up and getting this error- 'headers' member of RequestInit could not be converted to any of: Headers, ByteStringSequenceSequence, ByteStringMozMap.
Vipin TyagiPosted Jun 30, 2016, 10:47 PM EDT
What about try block?
Debasis SahaTOP 100Posted Jun 30, 2016, 3:22 AM EDT
Nice one..
Kapi ShivharePosted Jun 30, 2016, 3:16 AM EDT
Nice
Prasham SabadraPosted Jun 29, 2016, 8:56 PM EDT
Thanks for Sharing!
Santhakumar MunuswamyPosted Jun 29, 2016, 8:40 PM EDT
Thank you for nice article
RajaPosted Jun 29, 2016, 8:24 PM EDT
Nice Share...
kalu singh raoPosted Jun 29, 2016, 6:57 PM EDT
Nice...