Topic on Talk:VisualEditor

Adding button to apply smallcaps template to selected text

5
83.36.48.202 (talkcontribs)

Hello. I am trying to add a button to Visual Editor, to apply smallcaps template to selected text. So far, I have been able to create the button, following the example at VisualEditor/Gadgets/Add a tool. Now I can insert some fixed text in smallcaps, with this code: var myTemplate = [ {

type: 'mwTransclusionBlock',
attributes: {
 mw: {
  parts: [ {
   template: {
    target: {
     href: 'Template:Smallcaps',
     wt: 'Smallcaps'
    },
    params: {
     1: {
      wt: 'my parameter'
     }
    }
   }
  } ]
 }
}

}, {

type: '/mwTransclusionBlock' 

} ]; And then assigning it to a toolbar button, as described in VisualEditor/Gadgets/Add a tool. Now, the next step is replacing the fixed text 'my parameter', with the selected text from the editor. I have very little knowledge of Javascript, maybe this is a trivial issue but I don't know how to deal with it. Any help is much appreciated.

Whatamidoing (WMF) (talkcontribs)
83.36.48.202 (talkcontribs)

@Whatamidoing (WMF) Thanks for your response. It seems like that method could also work for me, with small modifications. Could you tell me where and how are you inserting that code? I tried to insert it the same way as my previous code, but it didn't work for me.

83.46.41.89 (talkcontribs)

I found the solution myself. This topic gives an example of exactly what I am trying to achieve, as a gadget: Topic:Vfmg4amjkxvrlhjp

Whatamidoing (WMF) (talkcontribs)

Congratulations. I'm glad that you found that.

Reply to "Adding button to apply smallcaps template to selected text"