Knapsack

approvedunreviewed

by bobstanton

Editor, tester and note creator for Knap templates.

↓ 2 downloadsUpdated 1d agoAGPL-3.0

Knapsack

Editor, tester and note creator for Knap templates.

Testing a template

Using a knap template, Templates/Recipe.knap:

---
{{ author | wikilink | yaml_property:"author" }}
{{ servings | yaml_property:"servings" }}
{{ url | yaml_property:"source" }}
---

{{ title | h1 }}

{{ description | blockquote }}

## Ingredients

{{ ingredients | table:("Ingredient", "Quantity") }}

## Instructions

{{ instructions | list:numbered }}

Add a knapsack block to a note with data for the fields in the knap template:

```knapsack
template: Templates/Recipe.knap
data:
  author: Eric Kim
  servings: 8
  url: https://example.com/gochujang-cookies
  title: Gochujang caramel cookies
  description: Chewy sugar cookies with a ribbon of spicy caramel.
  ingredients:
    - [Unsalted butter, 1/2 cup]
    - [Dark brown sugar, 1/4 cup]
    - [Gochujang, 1 tablespoon]
    - [All-purpose flour, 1 1/2 cups]
  instructions:
    - Mix the caramel ingredients until smooth.
    - Make and chill the cookie dough.
    - Swirl in the caramel, shape, and bake.
```
SettingMeaning
templateVault path or [[wikilink]] of the template file
dataVariables for the template, or the path or [[wikilink]] of a note whose properties to use
rendertrue shows the preview as formatted Markdown instead of its source. What is copied or made into a note is the source either way
previewfalse hides the generated Markdown
fieldsInputs that turn the block into a form; see below
outputFolderFolder for created notes; made if missing. Setting it adds a Create note button, with or without fields

Creating a note

Set a outputFolder and fields types. Each field becomes an input, and the result can be made into a note or copied.

```knapsack
template: Templates/Recipe.knap
outputFolder: Recipes
data:
  servings: 8
fields:
  title: text
  author: text
  servings: number
  url: text
  description: text
  instructions: list
```
Field typeInput
textOne line of text
numberA number
checkboxA toggle
dateA date picker
listSeveral values, separated by commas
noteA note, chosen from suggestions; the template gets its name
notesSeveral notes, separated by commas
[first, second, third]A dropdown of those choices

Defaults can be provided in data. New notes are named after title or name field

Suggestions from a property

A text or list field suggests values other note's property values. To take suggestions from a different property, name it after the type:

```knapsack
template: Templates/Recipe.knap
fields:
  author: text                # values of the author property
  stars: text Rating          # values of the Rating property
  course: list Meal type      # property names may contain spaces
  tags: list                  # tags from properties and from note text
```

Notes from a folder

note and notes suggest every note in the vault. Name a folder after the type to offer only its notes: author: note People.

Required fields

End a field's name with * to require it: title*: text. A form with an empty required field cannot be copied or made into a note.

Styling

SelectorPart
.knapsack-blockThe whole block
.knapsack-formThe inputs and buttons
.knapsack-fieldOne field's row, with data-field (its name), data-type, and data-required
.knapsack-missingA required field left empty
.knapsack-actionsThe row of buttons
.knapsack-previewThe generated Markdown and any messages
.knapsack-error, .knapsack-warningMessage blocks

Network requests

None.

Background tasks

None.

Dependencies

LibraryPurpose
knapTemplate rendering and syntax highlighting
monkey-aroundOpening .knap.md files in the template editor

The suggestions and delimiter pairing in src/vendor are copied from the Knap playground.

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.