custom post data show in editor



  • I've got some custom fields that I have working in my composer, but I'd like to be able to show the data that was submitted when editing posts. I tried passing it in as templateData when composer.build is called, but it only seems to be called when you have the composer as a separate route, which I don't want.

    tl;dr I have data in postData that I want to show/be editable by users while editing their posts, how do I get it into composerData? thanks!



  • Is this not a thing that's possible? It feels pretty basic.


  • Admin

    It is possible using two hooks.

    Server side you need "filter:composer.push"

    myPlugin.onComposerPush = function (hookData, callback) {
    	// called when composer is opened to edit a post
    	posts.getPostField(hookData.pid, 'myCustomField', function (err, customField) {
    		if (err) {
    			return callback(err);
    		}
    		hookData.myCustomField = customField;
    		callback(null, hookData);
    	});
    };
    

    Client side you need "filter:composer.create"

    $(window).on('filter:composer.create', function (ev, data) {
    	data.createData.myCustomField = parseInt(data.postData.myCustomField, 10) === 1;
    });
    

    After adding those two hooks myCustomField will be available to use in the the composer template.



  • excellent! thank you very much


 

| |