0

We are using O365/Sharepoint Online 2013.

I was wondering if there is a way to use links in Global Navigation Bar (Not the suite bar) that would reference the site the user is on at the moment. Why do I ask this? Because I tried to make a link to new document library creation and it's working perfectly but as there are subsites that should have the link too, they have the wrong URL in the link.

To clear it up a bit:

We have document centers and they have subsites. Subsites are inheriting the Global Navigation from the main document center sites. I found this link that can be used as a "shortcut" link/button to create a document library:

https://example.sharepoint.com/site/_layouts/15/new.aspx?ListTemplate=101&

But the problem is that in the subsites the URL is the same so it's creating the new library to the main document center site. So I was wondering if there is some "token" or parameter or another method to use to get the URL to reference the current site? I found tokens {site} and ~site but they do not work in the Global Navigation. I tried but it just gives me an error about not starting the URL with http://, https://, /, etc.

I also tried to use

https://example.sharepoint.com/~site/_layouts/15/new.aspx?ListTemplate=101& 
and
https://example.sharepoint.com/{site}/_layouts/15/new.aspx?ListTemplate=101& 

but it didn't work as the link just read like that and the site tokens didn't transform into the current site.

Thank you a lot for any information on this matter! :)

1

You can use Javascript to build this Url. Just reference your new .js file into masterpage. All the code should be run on document ready.

$(document).ready(function(){ //your code }))

You can build Url and replace the shortcut href attribute value on many ways:

  • var url = SP.Utilities.Utility.getLayoutsPageUrl("new.aspx") + "_layouts/15/new.aspx?ListTemplate=101"
  • var url = _spPageContextInfo.webServerRelativeUrl + "_layouts/15/new.aspx?ListTemplate=101"

At the end you manipulate DOM element - link. $("#newLib").attr("href",url)

Or better yet - use JSOM and add CustomAction to include Javascript http://aaclage.blogspot.com/2013/12/how-to-include-user-custom-actions-and.html

  • Sorry I'm a bit new to Javascript so one question came to my mind. Should I add all those lines into notepad and save is as .js file? And then upload that file into Sharepoint and reference it in my masterpage? After I've done that, how can I determine where to show that link (reference it in navigation settings etc?) :) – Tenttu Aug 25 '14 at 8:44
  • Yes, just like that. Save it to one of the libraries in Sharepoint (can be any Document library, most of the time Style Library is used or _catalogs/masterpage/<newFolderName> ). CheckIn file after edit. To include reference in masterpage to this .js file you can check this blog post how to do it link and this for showing a link on site link – displayName Sep 4 '14 at 19:27
  • Thank you for your comment but I'm sorry I must say that I still can't grasp on how to do all that. When I said "I'm a bit new to Javascript" it was actually an understatement as I really can't write any JS or even understand a lot of the mechanics/logic in it and even Sharepoint's advanced features like those Custom Action and DOM -things are in the dark. That said, if possible, could you give me "for dummies" -version or steps on how to do what I asked in my original question? Of course I understand if you do not have time for that! Anyways thanks for all the help & information this far! :-) – Tenttu Sep 5 '14 at 5:57
  • Oh, then you should first check jQuery. Or you can contact me and I will make you this solution. – displayName Sep 5 '14 at 10:47

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.