How to customize templates
Hi,
Does somebody know how to customize templates ?
The doc says : https://github.com/rtfpessoa/diff2html#configuration
For example, I would like to customize the "generic-wrapper". (See : https://github.com/rtfpessoa/diff2html/blob/master/src/templates/generic-wrapper.mustache)
But I don't see how to that in options. I suppose I need to replace the "global.browserTemplates["generic-wrapper"]" with something like that :
diff2htmlUi.draw(
'#diff,
{
templates: () => {
global.browserTemplates["generic-wrapper"] = "<div class=\"d2h-wrapper\"></div>";
}
}
);
But my IDE say : the property "browserTemplates" does'nt exist on type "Global".
Thanks
Hi @J2BB for exact usage details check https://github.com/rtfpessoa/diff2html/blob/c2c253d3e3f8b8b267f551e659f72b44ca2ac927/test/hogan-cache-tests.js#L39
I have both types used there. The only difference is that you are passing the config to Diff2html and not HoganJsUtils since it is a hidden component.
Let me know if you have any more questions if everything is fine close this please
Hi @rtfpessoa ,
Thank you for this fast answer, it works perfectly !
Solution :
var HoganJsUtils = new (require('../../../../node_modules/diff2html/src/hoganjs-utils.js').HoganJsUtils)();
diff2htmlUi.draw( '#diff', { templates: { 'generic-wrapper': HoganJsUtils.compile('<div class="d2h-wrapper"></div>') } } );
Thanks !
Ok, now I understand your problem.
That is definitely a recommended way, you should use the rawTemplates. The idea is that I will compile the rawTemplates and templates is only if you want to depend on hogan and compile them yourself.
Ok, so i will prefer this way :
{ rawTemplates: { 'generic-wrapper': HoganJsUtils.compile('<div class="d2h-wrapper"></div>') } }
?
No, you just need the HTML:
{ rawTemplates: { 'generic-wrapper': '<div class="d2h-wrapper"></div>' } }
Oh ok ;)
And another question : what is the best way to customize the content of the "d2h-file-header" block in a side-by-side diff ?
See : https://github.com/rtfpessoa/diff2html/blob/master/src/templates/line-by-line-file-diff.mustache
Currently I guess you would have to completely replace the side-by-side-file-diff template. But I would also be open for a PR separating it into it's own template.