Search code examples
emacselisporg-mode

Including literal HTML code in org-mode templates


In org-mode, when you export HTML projects you can use templates to give all exported pages the same options, this is described here http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html. What I would like to do, is give all exported pages an HTML snippet, for analytics, which is not an option. Is this possible with org-templates?

Now, I tried to add literal HTML code to the base template level-0-template.org with

#begin_html
...
#end_html

but it didn't work out. Does anyone know how to add html code to each HTML file that is exported in the project?

My project is organized as follows:

|- org
   |- index.org
|- html
   |- index.html (this is exported)
|- templates
   |- level-0.org (I'd like to include default html here)
|- org_publish.el (this is the publishing config file) 

Solution

  • To expand on my comment in the question, here is the difference between #+setupfile: and #+include:.

    Details about both are available in the Org-Mode manual. See Setup File and Include Files.

    The setupfile is essentially a list of all org configurations that are included in the linked file. It will pass things such as #+options. It will not however include any other content that the original file might include.

    On the other hand, #+include: inserts the content of the linked file wherever the line is inserted. It acts similarly to \input in LaTex. I'm not certain to what degree it will bring along any org-configuration settings from the linked file, you may need to both #+include and #+setupfile the file to ensure everything is present. However since you do want the body content of the file to be included in each, you have to use #+include to insert it.