cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the site title

vince20151
Champ in-the-making
Champ in-the-making
I'm in share Javascript and writing code for a page in a site. I have access to page.url.templateArgs.site which gives me the site id. How do I get the site title from this site Id string?

I think I can get to the site title or site description if I can get to the site object. However, I don't know how to get the site object for the current site. I tried this code but get error "org.mozilla.javascript.EcmaError: ReferenceError: "siteService" is not defined."

var mysite = siteService.getSite(page.url.templateArgs.site);

Do I have to include some standard JS in the header?

FYI - I'm customizing this JS \webapps\share\WEB-INF\classes\alfresco\web-extension\site-webscripts\org\alfresco\components\dashboard\customise-dashlets.get.js to detect if the site title contain certain name and flag certain dashlets as not visible. I can evaluate the site shortname (ID) but I need to evaluate the site title instead.

Thanks a bunch!
3 REPLIES 3

fstnboy
Champ on-the-rise
Champ on-the-rise
Hi vince20151,

The siteService is only available in the repository side (Alfresco, not Share) javascript. From your javascript you'll need to call a webscript that returns you the Site information. You might need to create your own webscript for that.

vince20151
Champ in-the-making
Champ in-the-making
Thank you fstnboy. It is a bit confusing but I understand that concept now. I need to create an Alfresco webscript and call it from within my share page to get that info.
Thanks a bunch!

niketapatel
Star Contributor
Star Contributor
Hi vince20151

You can not access Alfresco js API in share webscript's js. This is only accessible from Alfresco webscript's js file.

To solve your issue

You can use below code snippet in share js


  var siteId = page.url.templateArgs.site; //get site Id
  var json = remote.call("/api/sites/" + siteId); //Call alfresco OOB webscript for site detail which includes title
  var obj = eval('(' + json + ')'); // parse JSON object
 
  var siteTitle = obj.title; //get title from json