0

I have a simple js example to try. Here the code:

(function () {

    var overrideContext = {};
    overrideContext.Templates = {};
    overrideContext.Templates.Item = overrideTemplate;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideContext);

    })();

function overrideTemplate(ctx) {
    return "<div style='font-size:32px;border:solid 1px Silver;'>" + ctx.CurrentItem.Title + "</div>";
} 

after that I simply add this js to site assets and set into webpart properties. But nothing happens...

enter image description here

and nothing is changed... enter image description here

Am I missing something?

4
  • Did you check whether the JSLink file is loaded? You can use the developer toolbar of your browser to see which script files are loaded.
    – Suleyman
    Jun 29, 2016 at 10:49
  • nice question. I did it, but i can´t see the js file inside dev tools (IE and Chrome). I try alert("boo"), inside js file too, but not working. I think that js file is not loading... but why?
    – rockxl1
    Jun 29, 2016 at 11:02
  • Save yourself some head-aches and use Chrome + the Cisar CSR extension Jun 29, 2016 at 11:12
  • nice extension! use this extension the code runs! but with out set F12 and click on Cisar the code doesn´t work... why=?
    – rockxl1
    Jun 29, 2016 at 11:28

1 Answer 1

0

In your webpart properties, instead of refering the JS file with absolute URl refer like this

~sitecollection/SiteAssets/XTR/JSTest.js

Instead of Site Collection URL, specify ~sitecollection

7
  • I try: ~/SiteAssets/XTR/JSTest.js, ~SiteAssets/XTR/JSTest.js , /Sites/Portal/SiteAssets/XTR/JSTest.js, ... allways the same . Is because the SiteAssets library?
    – rockxl1
    Jun 29, 2016 at 11:01
  • try something like above now, if it doesnt works still give me you JS file complete URL and your site collection URL Jun 29, 2016 at 11:04
  • is intranet... i did all tries..
    – rockxl1
    Jun 29, 2016 at 11:07
  • where is your js file? site collection level or subsite level? Jun 29, 2016 at 11:08
  • site leve colletion, localhost/Sites/Portal/SiteAssets/XTR/JSTest.js and the page is in the same site colletion
    – rockxl1
    Jun 29, 2016 at 11:09

Your Answer

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

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