Skip to content

Instantly share code, notes, and snippets.

@montylounge
Last active December 18, 2015 08:29
Show Gist options
  • Select an option

  • Save montylounge/5754082 to your computer and use it in GitHub Desktop.

Select an option

Save montylounge/5754082 to your computer and use it in GitHub Desktop.
Cactus plugin to place current page and directory path list in context. Most applicable for setting active nav items, breadcrumbs, etc.
def preBuildPage(site, page, context, data):
"""
Cactus plugin to provide current page and directory path list to template.
Examples:
Request: /sports/team/foo.html
CURRENT_PAGE: foo.html
PAGE_DIR_PATH: ['sports', 'team']
"""
directory_path = page.path.split("/")
current_page = directory_path.pop()
context['DIRECTORY_PATH'] = directory_path
context['CURRENT_PAGE'] = current_page
return context, data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment