mw.hook( 've.activationComplete' ).add( function () { // Some code to run when edit surface is ready var surface = ve.init.target.getSurface(); if ( surface.getMode() === 'visual' ) { // Visual mode var surfaceModel = ve.init.target.getSurface().getModel(); surfaceModel.getFragment().collapseToEnd().insertContent( [ { type: 'mwTransclusionInline', attributes: { mw: { parts: [ { template: { target: { href: 'Template:Inhalt', wt: 'Inhalt' }, params: { 1: { wt: 'Mitraspera' }, 2: { wt: '-' }, 3: { wt: '-' }, 4: { wt: '2019' } } } } ] } } } ] ).collapseToEnd().select(); } else if ( surface.getMode() === 'source' ) { // Source mode } } );