1

I need to add custom button of template /sitecore/templates/System/WebEdit/WebEdit Button to RTE in Experience Editor. And invoke my custom js function on click. How I can implement that?

I've added my function in js-file and included file in

<clientscripts><everypage> </everypage></clientscripts>

I've tried invoke my function from Command using

 Sitecore.Context.ClientPage.ClientResponse.Eval("myFunction()")

and I've tried to add

javascript:myFunction() 

in Click field of sitecore item. But my function is always undefined.

How can I add javascript with my function to EE and call it for my custom button?

  • Does your "myFunction()" call is available from browser console? – Anton Jan 15 '19 at 13:28
  • @Anton no, I see undefined. Is there a specific way to add js script in EE mode? – Val Yar Jan 15 '19 at 13:42
  • a lot of ways to do it, check this article jammykam.wordpress.com/2017/07/24/… One of possible ways: @if (Sitecore.Context.PageMode.IsExperienceEditor) { <script src="pathtojs"></script> } – Anton Jan 15 '19 at 14:01
  • @Anton thanks, I'll try to add pipeline. My project is sitecore module, not a site. – Val Yar Jan 15 '19 at 15:13
0

I didn't find any other working way to do that, only this patch works for me

<pipelines>
  <group groupName="ExperienceEditor" name="ExperienceEditor">
    <pipelines>
      <pageEditingScripts>
        <processor type="Sitecore.ExperienceEditor.Pipelines.PageEditingScripts.AddDeclaredScripts, Sitecore.ExperienceEditor">
          <path patch:after="*[last()]">/sitecore modules/Shell/MyApp/js/myCustom.js</path>
        </processor>
      </pageEditingScripts>
    </pipelines>
  </group>
</pipelines>

So, I added my custom js to list of paths and as I got, it will be bundled with others scripts for EE.

| improve this answer | |

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.