helper-link-to

0.3.0 • Public • Published

helper-link-to NPM version NPM monthly downloads Linux Build Status

Templates helper that returns a link path from the current view to the another view.

Install

Install with npm:

$ npm install --save helper-link-to

Usage

This helper should be used with an app created with templates or something that inherits from templates. See related projects for some apps that use templates

With assemble and engine-handlebars

Setup the helper by registering it with the app:

// assemble is a descendant of `templates`
var app = assemble();
app.engine('hbs', require('engine-handlebars'));
 
// engines like handlebars can handle a helper name with dashes
app.helper('link-to', require('helper-link-to'));

Use the helper in a handlebars template:

<a href="{{link-to 'about'}}">About</a>

Creates output like:

<a href="./about.html">About</a>

With verb and engine-base

Setup the helper by registering it with the app:

// verb is a descendant of `templates`
var app = verb();
app.engine('md', require('engine-base'));
 
// engines like `engine-base` cannot handle a helper name with dashes
app.helper('linkTo', require('helper-link-to'));

Use the helper in a template:

 - [Getting Started][{%= linkTo("getting-started", "docs") %}]

Creates output like:

 - [Getting Started][docs/getting-started.md]

API

linkTo

templates helper that creates a link from the current view to the specified view on the specified collection.

Params

  • key {String|Object}: Name of the view to lookup to link to. May also pass in a view instance link to.
  • name {String}: (optional) Name of the collection to search for the view. (default="pages")
  • props {Array}: Optional array of properties to check when getting the destination path from a view. May use dot notication (data.permalink). (default=["data.path", "dest", "path"])
  • returns {String}: Relative path to the specified view from the current view.

Example

{{! Handlebars example linking from "home.html" to "about.html" in the default "pages" collection }}
<a href="{{link-to 'about'}}">About</a>
 
<!-- Handlebars example linking from "home.html" to "blog/post-1.html" in the "posts" collection -->
<a href="{{link-to 'post-1' 'posts'}}">Post 1</a>

About

Related projects

  • assemble-core: The core assemble application with no presets or defaults. All configuration is left to the… more | homepage
  • assemble: Get the rocks out of your socks! Assemble makes you fast at creating web projects… more | homepage
  • engine-base: Default engine for Template. | homepage
  • engine-handlebars: Handlebars engine, consolidate.js style but with enhancements. This works with Assemble, express.js, engine-cache or any… more | homepage
  • generate: Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… more | homepage
  • handlebars: Handlebars provides the power necessary to let you build semantic templates effectively with no frustration | homepage
  • relative-dest: Calculate the relative path from a file's destination path to another directory or file. | homepage
  • relative: Get the relative filepath from path A to path B. Calculates from file-to-directory, file-to-file, directory-to-file… more | homepage
  • templates: System for creating and managing template collections, and rendering templates with any node.js template engine… more | homepage
  • update: Be scalable! Update is a new, open source developer framework and CLI for automating updates… more | homepage
  • verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Contributors

Commits Contributor
36 doowb
8 jonschlinkert

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Brian Woodward

License

Copyright © 2017, Brian Woodward. Released under the MIT License.


This file was generated by verb-generate-readme, v0.5.0, on April 12, 2017.

Package Sidebar

Install

npm i helper-link-to

Weekly Downloads

14

Version

0.3.0

License

MIT

Last publish

Collaborators

  • jonschlinkert
  • doowb