Skip to content Skip to sidebar Skip to footer

I Would Like To Be Able To Load/edit Handlebars.js Templates ( Express Server ) By Clicking On A Hyperlink , Any Suggestions?

One of the most time-consuming portions of development on a handlebars.js app is finding the location of the template/partial that is being used for that specific piece of HTML. Is

Solution 1:

So I have managed to implement a workaround for this using Grunt.

Basically, it adds a button in the HTML page that can be clicked in the browser that opens that handlebars template in sublime for editing. Local

Express

exports.editfile = function(req, res,next) {
var filename = req.query['filename']
const { exec, spawn } = require('child_process');
exec('grunt editfile --filename='+filename, (err, stdout, stderr) => {
  if (err) {
    console.error(err);
    return;
  }
  console.log(stdout);
});
res.send('complete');
};

Grunt

//In the grunt init
  shell: {  
    'openfile':openFile(),
    }
    grunt.loadNpmTasks('grunt-shell');
function openFile(){
    var openString = ''var fileName = grunt.option('filename'); //get value of target, my_module
    openString = {
        command: [
        'cd..','cd..','cd..','cd '+process.env.ROOTFOLDER,
        'sublime_text.exe "'+fileName+'"',
        ].join('&&')
    }
    return openString
}

grunt.registerTask('editfile',[
    'shell:openfile'
    ]);

Handlebars

<a class="btn btn-outline-warning bt-sm adminedit" style="" data-filename="{{filename}}" id="{{uniqueid}}" onclick="editFile(this.id)" href="#"class="text-warning">edit</a>
<scripttype="text/javascript">functioneditFile(iditem){
  var editFilename = $('#'+iditem).attr("data-filename")
  $.ajax({
    url     : '/semini/admin/editfile/?filename='+editFilename,
    success : function( data ) {
      console.log('executing  : ',data)
    },
    error   : function( xhr, err ) {
      alert('Error',err);     
    }
  });   
}
</script>

Note, to get sublime to open from the CMD, you have to add an environment variable in windows. Not too difficult, just google.

It works great ..... but I cannot get a partial on handlebars to provide its name, and as such this only works for the first rendered page and not partials.

Post a Comment for "I Would Like To Be Able To Load/edit Handlebars.js Templates ( Express Server ) By Clicking On A Hyperlink , Any Suggestions?"