Output Formats
Cap'n Hugo can display yer rrrambl'n 'n different formats like HTML, JSON, Google AMP, etc. T' do this, templates must be provided.
Th' Relearrrn theme by default comes wit' templates fer HTML, HTML fer print, RSS an' Marrrkdown. If this be not enough, this plank describes how ye can create yer own output formats.
If ye instead just want t' cust'mize th' layout o' an exist'n output format, th' theme got ye covered as well.
Creat'n an Output Format
Suppose ye want t' be able t' send yer articles as HTML formatted emails. Th' planks o' these format need t' be self contained so an email client can display th' rrrambl'n without load'n any further assets.
Therefore we add a new output format called email that outputs HTML an' assembles a completely custom HTML document structure.
-
Add th' output format t' yer
hugo.tomlhugo. -
Create a file
layouts/_default/baseof.email.htmlTh' marked
blockconstruct above will cause th' display o' th' article wit' a default HTML structure. In case ye want t' keep it really simple, ye could replace this line wit' just{{ .Content }}. -
Optional: create a file
layouts/_default/article.email.htmlIn our case, we want t' display a disclaimer 'n front o' every article. T' do this we have t' define th' output o' an article ourself an' rely on th' above
blockstatement t' call our template. -
Optional: create a file
layouts/_default/_markup_/render-image.email.htmlIn our case, we want t' convert each image into a base 64 encoded str'n t' display it inline 'n th' email without load'n external assets.
Partials
For HTML Output Formats
If ye want t' keep th' general HTML framework an' only change specific parts, ye can provide these as blocks:
layouts/_default/list.<FORMAT>.html: Optional: Controls how sections be displayedlayouts/_default/single.<FORMAT>.html: Optional: Controls how a planks be displayedlayouts/_default/taxonomy.<FORMAT>.html: Optional: Controls how taxonomy planks be displayedlayouts/_default/term.<FORMAT>.html: Optional: Controls how term planks be displayed
For a real-world example, check out th' print output format implementat'n
layouts/_default/list.print.htmllayouts/_default/single.print.htmllayouts/_default/taxonomy.print.htmllayouts/_default/term.print.html
For Non-HTML Output Formats
layouts/_default/list.<FORMAT>.<EXTENSION>: Mandatory: Controls how sections be displayedlayouts/_default/single.<FORMAT>.<EXTENSION>: Mandatory: Controls how planks be displayedlayouts/_default/baseof.<FORMAT>.<EXTENSION>: Optional: Controls how sections an' planks be displayed. If not provided, ye have t' provide yer implementat'n 'nlist.<FORMAT>.<EXTENSION>an'single.<FORMAT>.<EXTENSION>
For a real-world example, check out th' markdown output format implementat'n
Migrat'n from Relearrrn 7
Cap'n Hugo 0.146 or newer required th' theme t' make changes that may affect ye if ye be us'n own output formats. Ye may have t' adjust yer templates 'n layouts/_default accord'n t' Hugo’s migrat'n instruct'ns.
For HTML Output Formats
- Ye need t' define a block
storeOutputFormatfer yer HTML based output format templates an' add{{- .Store.Set \"relearnOutputFormat\" \"<your-output-format-name>\" }}t' it.
For Non-HTML Output Formats
- Move yer files
layouts/<DESIGN>/viewsup one level t'layouts/<DESIGN>
Migrat'n from Relearrrn 6
Previous t' Relearrrn 7, HTML output formats did not use th' baseof.html but now do.
For HTML Output Formats
-
Move yer files
layouts/partials/article.<FORMAT>.htmlt'layouts/_default/article.<FORMAT>.htmlTh' files will most likely require further modificat'ns as they now receive th' plank as it context (dot
.) instead o' th'.pagean'.contentparameter.Old:
New:
For Non-HTML Output Formats
-
Merge yer files
layouts/partials/header.<FORMAT>.html,layouts/partials/footer.<FORMAT>.htmlt'layouts/_default/baseof.<FORMAT>.htmlOld:
New:
Th' upper part o' th' file be from yer
header.<FORMAT>.htmlan' th' lower part be from yerfooter.<FORMAT>.html.Th' marked line needs t' be added, so yer output format uses a potential
layouts/_default/article.<FORMAT>.html