{"action":"created","issue":{"url":"https://api.github.com/repos/knockout/knockout/issues/1458","repository_url":"https://api.github.com/repos/knockout/knockout","labels_url":"https://api.github.com/repos/knockout/knockout/issues/1458/labels{/name}","comments_url":"https://api.github.com/repos/knockout/knockout/issues/1458/comments","events_url":"https://api.github.com/repos/knockout/knockout/issues/1458/events","html_url":"https://github.com/knockout/knockout/issues/1458","id":37950929,"number":1458,"title":"Add \"createTemplate\" to Component Templates analogous to createViewModel","user":{"login":"sccooper","id":8176341,"avatar_url":"https://avatars.githubusercontent.com/u/8176341?v=3","gravatar_id":"","url":"https://api.github.com/users/sccooper","html_url":"https://github.com/sccooper","followers_url":"https://api.github.com/users/sccooper/followers","following_url":"https://api.github.com/users/sccooper/following{/other_user}","gists_url":"https://api.github.com/users/sccooper/gists{/gist_id}","starred_url":"https://api.github.com/users/sccooper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sccooper/subscriptions","organizations_url":"https://api.github.com/users/sccooper/orgs","repos_url":"https://api.github.com/users/sccooper/repos","events_url":"https://api.github.com/users/sccooper/events{/privacy}","received_events_url":"https://api.github.com/users/sccooper/received_events","type":"User","site_admin":false},"labels":[{"id":85252038,"url":"https://api.github.com/repos/knockout/knockout/labels/affected:%20few","name":"affected: few","color":"b0d8b0","default":false},{"id":85250171,"url":"https://api.github.com/repos/knockout/knockout/labels/severity:%20minor","name":"severity: minor","color":"e17d81","default":false},{"id":85251605,"url":"https://api.github.com/repos/knockout/knockout/labels/type:%20feature","name":"type: feature","color":"207de5","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":21,"created_at":"2014-07-16T05:45:42Z","updated_at":"2016-12-03T01:20:56Z","closed_at":"2016-12-03T01:20:55Z","body":"I would like custom elements to be allowed to define just a view model and leave the template up to a 3rd party designer on a per element basis, so templates for components could use the html between the custom element tags or be specified as a parameter, e.g.:\n\n```\n<my-component>\n<span data-bind=\"text: foo\"></span>\n</my-component>\n```\n\nor:\n\n```\n<my-component params=\"custom-template: 'custom-id'\"></my-component>\n```\n\nI added this functionality by allowing templates to have a createTemplate property when registering custom elements that is a function that takes (data, info) like createViewModel does.\n\nI can then implement the functionality I want like this:\n\n```\nko.components.register(\"my-component\", {\n    viewModel: { ... },\n    template: {\n        createTemplate: function (data, info) {\n            if (data[\"something\"]) {\n                return \"<something></something>\";\n            } else {\n                return {\n                    element: info.element\n                };\n            }\n        }\n    }\n});\n```\n\nI think this approach is generally useful, but it does affect loaded configs which now have a createTemplate property when resolved, not a template property that is an array of nodes. I have tried to handle existing loaders by first looking for the template property. \n\nWould you like to see the patch or is there a better way of doing this?\n"},"comment":{"url":"https://api.github.com/repos/knockout/knockout/issues/comments/264604168","html_url":"https://github.com/knockout/knockout/issues/1458#issuecomment-264604168","issue_url":"https://api.github.com/repos/knockout/knockout/issues/1458","id":264604168,"user":{"login":"mbest","id":1230364,"avatar_url":"https://avatars.githubusercontent.com/u/1230364?v=3","gravatar_id":"","url":"https://api.github.com/users/mbest","html_url":"https://github.com/mbest","followers_url":"https://api.github.com/users/mbest/followers","following_url":"https://api.github.com/users/mbest/following{/other_user}","gists_url":"https://api.github.com/users/mbest/gists{/gist_id}","starred_url":"https://api.github.com/users/mbest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbest/subscriptions","organizations_url":"https://api.github.com/users/mbest/orgs","repos_url":"https://api.github.com/users/mbest/repos","events_url":"https://api.github.com/users/mbest/events{/privacy}","received_events_url":"https://api.github.com/users/mbest/received_events","type":"User","site_admin":false},"created_at":"2016-12-03T01:20:55Z","updated_at":"2016-12-03T01:20:55Z","body":"I'm closing this since there's a suitable way to extend Knockout to get the desired functionality."}}
{"actor":{"display_login":"mbest"}}