1

We have websites with URL's like this: /sitename/site/DE123

We want to add a link on this website which looks so: /sitename/site/SitePages/Test.aspx?FilterName=Kostenstelle&FilterMultiValue=*123*

Is it possible to add a link on this website which changes automatically the FilterMultipleValue into the number of the current URL number? We work with site templates. It will be great if the link on the new site changes automatically.

1 Answer 1

1

You could achieve this by using JavaScript/jQuery to build the url. Add the following piece of code to your masterpage:

ExecuteOrDelayUntilScriptLoaded(function() {
 var webUrl = _spPageContextInfo.webAbsoluteUrl;
 var urlPathPrefix = webUrl.substring(0, webUrl.lastIndexOf('/') + 1);
 var webTitle = webUrl.substring(webUrl.lastIndexOf('/') + 1);
 var webNumber = /\d+/.exec(webTitle);

 if(webNumber) {
  var number = webNumber[0]; //index will vary 
  //Build New Url
  $('<a>', { class: 'ms-storefront-appiconspan ms-textXLarge', text: 'Test Page', href: urlPathPrefix + 'SitePages/Test.aspx?FilterName=Kostenstelle&FilterMultiValue=*' + number + '*', style: 'color: #FFFFFF' } )
          .appendTo($('#s4-bodyContainer'));
 }
 else {
  window.console && console.log('No number found in the web Title');
 }
}, "sp.js");
2
  • Is it possible to add this code to a content editor webpart or to the html form webpart? I can't work with the sharepoint designer to change the masterpage...
    – Tiac
    Commented Mar 27, 2014 at 7:38
  • You sure can but the link would only appear in the pages that you add content webpart to.
    – Aveenav
    Commented Mar 27, 2014 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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