0

Using JavaScript in SharePoint Online how can I get the current site's theme name?

I'm writing a script that needs to make some decisions based on whether the site is set to the default "Office" theme or not.

I've found examples online of how to do something similar using server-side code and plenty on how to set the theme but there seems to be a lack of information on how to read the theme data through JavaScript.

0

You can get ThemeInfo of current site using JavaScript or REST API.

REST API

Make a GET request to /_api/Web/ThemeInfo. Test/Explore REST API using SharePoint REST Client.

enter image description here

JavaScript

var context = new SP.ClientContext.get_current();
var web = context.get_web();
var themeInfo = web.get_themeInfo();
context.load(themeInfo);
context.executeQueryAsync(onSuccess, onError);

function onSuccess() {
    console.log(themeInfo.get_accessibleDescription());
    console.log(themeInfo.get_themeBackgroundImageUri());
}

function onError(sender, args) {
    console.log(args.get_message());
}

Find methods and properties of ThemeInfo here.

  • Thanks Atish. I'd come across ThemeInfo but I couldn't see from that how I can get the theme's title. So whether it's "Office","Sea Monster","Wood" etc. – James Buckingham Sep 1 '16 at 7:55
  • It seems it's not exposed in REST API or JSOM – Atish Dipongkor - MVP Sep 1 '16 at 9:36
  • Thanks for confirming that Atish. I'll need to use a workaround in that case and see if I can use a combination of the get_accessibleDescription and get_themeBackgroundImageUri methods to work out a pattern with the theme. – James Buckingham Sep 1 '16 at 12:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.