Hype Template Export Script

I made a generic export script to manage templates. It uses a document variable and then looks for the Hype Resources and thereafter, the export script folder for an HTML file called like the document variable. The template variable defaults to template if nothing is assigned.

Using a default named template

  1. Add a HypeTemplate.html file to your resource folder and you're done

Using a custom named template

  1. Assign a name under DocumentExport Script Arguments (example: customName)
  2. It will then look for the file customName.html in the resources folder
  3. It will then look for the file customName.html in the export script folder

It then loads the HTML file and replaces all sorts of variables in the template. Giving you a pretty generic template engine. Here is the full file for anybody to play with…

Here is an example Template (HTML)…


This approach allows using any template and even bundle them with the Hype Document…
If you prefer, you can also keep the templates in your export script folder.

Manual Installation Guide

Thanks to @jonathan for the great manual guide


  1. Go to the GIST Page and "Download ZIP" from: Hype Template · GitHub
  2. Open the /Applications/Utilities/Terminal.app and enter in this command:
    open ~/Library/Application\ Scripts/com.tumult.Hype4

    This will open the Applications Scripts folder; alternatively, you can get to this via
    Hype's PreferencesExportingShow Export Scripts Folder in Finder

  1. Move the HypeTemplate.hype-export.py file into the com.tumult.Hype4 folder
  2. Back in the Terminal, enter this command:
    chmod 755 ~/Library/Application\ Scripts/com.tumult.Hype4/HypeTemplate.hype-export.py

    This will give the export script permission to run.

Creating your template with the available variables

  1. Create a new template or use the example above as a starting point
  2. Use the variables provided by the script in your template
Variable Name Description
containerWidth the width of the Hype container without units and independent of responsive settings
containerHeight the height of the Hype container without units and independent of responsive settings
htmlFilename the name of the HTML file to be exported
customHeadHTML contains any user code added in the Head HTML tab
documentLoaderHTML contains the HTML code that loads the Hype document (including the wrapper)
title contains the document title
hypeDocumentStyles contains the style attribute content for the Hype documentdiv wrapper
hypeDocumentId contains the Hype document ID
documentLoaderScriptSource contains the source of the script that loads the Hype document
documentLoaderScriptPath contains the path of the script that loads the Hype document
documentLoaderFilename contains the name of the script that loads the Hype document
hypeDocumentStyleWidth contains the width of the div that contains the Hype document
hypeDocumentStyleHeight contains the height of the div that contains the Hype document
hypeDocumentStyleWidthValue contains the width value of the div that contains the Hype document
hypeDocumentStyleHeightValue contains the height value of the div that contains the Hype document
hypeDocumentStyleWidthUnit contains the width unit of the div that contains the Hype document
hypeDocumentStyleHeightUnit contains the height unit of the div that contains the Hype document
cacheBuster contains a random number to prevent caching of the exported document (doesn't include ?)
viewportMetaTag contains the contents of the <meta name="viewport" ... tag
  1. Add your template as HypeTemplate.html to your project (autoloads) or use an arbitrary name but in that case, you would need to enter it under DocumentExport Script Arguments

  2. Chose HypeTemplate as your export script for previews or when exporting

Using the JavaScript bundling feature

  1. Add a file called HypeTemplate.js to your project.
  2. Edit it and add all your JavaScript you would like to bundle
  3. Chose HypeTemplate as your export script for previews or when exporting
7 Likes

Very cool approach!

Updated the example:

  • fixing the extraction of the viewport meta
  • Rename the document argument parameter to Template name
  • Renamed the default template to HypeTemplate.html
  • Added the feature of HypeTemplate.js being prepended to *_hype_generated_script.js allowing to bundle custom scripts into said file
1 Like

↑ look at project
I updated the description with all the variables and a better guide, thanks to @jonathan

1 Like

↑ look at project
I updated some typos and streamlined some variable name, thanks to @Daniel