Skip to content

Instantly share code, notes, and snippets.

@lucasbrigida
Forked from balupton/README.md
Created September 8, 2013 05:56
Show Gist options
  • Save lucasbrigida/6482231 to your computer and use it in GitHub Desktop.
Save lucasbrigida/6482231 to your computer and use it in GitHub Desktop.

DocPad: Absolute URL Helper

Uses a docpad configuration file to specify template data that we can use in our document to generate absolute urls.

module.exports =
# =================================
# Template Data
# These are variables that will be accessible via our templates
templateData:
# Site Information
site:
# Site Production URL
url: 'http://your-website.com'
# -----------------------------
# Helpers
# Get the Absolute URL of a document
getUrl: (document) ->
return @site.url + (document.url or document.get?('url'))
Via helper: <a href="<%= @getUrl(@document) %>">visit me</a>
Without helper: <a href="<%= @site.url+@document.url %>">visit me</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment