4

I would like to have the text file associated with my content editor change based upon the query string.

?division=Name

Content Editor link:

/site assets/[QueryStringResult].txt
  • I am not aware of anyway to do this but you could achieve the same result by adding some jQuery to your text file which altered the output based on the query string parameter? – Dave Paylor Mar 15 '13 at 21:59
  • Dave, Thank you. Yes, These documents already exsists, so I was just hoping there was a way to utilize the existing files. But there is possibly not away to do this. Thanks again – Shelly Miner Mar 16 '13 at 0:52
4

It could be achieved by generating url for the asset on the client side and passing it to iframe for displaying asset content in Content Editor web part.

Usage

Clear ContentLink property

Put in Content property of the following code:

<iframe width="100%" id="assetContent"  frameborder="0"></iframe>


<script type="text/javascript">

//get query string value
function getParameterByName(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function renderAssetContent() 
{
    var division = getParameterByName("division");
    if (division.length > 0){
        var assetUrl = "/teamsite/itdepteamsite/SiteAssets/" + division + ".txt"; 

        var assetContent = document.getElementById("assetContent");
        assetContent.setAttribute("src", assetUrl);
    }
}

renderAssetContent();
</script>
  • 1
    I should take a moment to thank you. Your solutions and pointers are amazing, I have been doing SP development for a few years now, I find a lot of value in your code and tips. I should laud your skills and above all you take time to answer questions, thanks again for contributing to the SP developer community. Best Regards, Avi – Avi Pawar May 3 '19 at 10:42
  • Good to know! Cheers! – Vadim Gremyachev May 3 '19 at 10:57

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.