# Obsidian Rule Engine
A plugin for [Obsidian](https://obsidian.md/) that lets you define rules to automate commands and render HTML views for your notes. Transform how your notes behave and are displayed by defining custom rules that match specific files.
_Expands on [anuwup/obsidian-custom-views](https://github.com/anuwup/obsidian-custom-views) (MIT license)._
**Features**
- render HTML templates on individual markdown files.
- render HTML templates on canvas nodes.
- render HTML templates on each `.base` item.
- automatically run list of commands against individual files.
- automatically run lists of commands against each `.base` item.

## Commands
Any command available in the current Obsidian context will be available to include in rules. When rules execute, only commands available in that context will run.
Rules are checked on individual files when they open. They are checked on `.base` results when they change. You can also use the 'process now' command to run rules on demand.
Commands from all matching rules wll execute in order.
### Provided commands
By default, commands provided by this plugin are disabled. You can enable them in the plugin settings.
- `Force template` - Apply a template to the current file regardless of rule automations and conditions.
- `Restore view` - Remove any applied templates from the current file.
- `Process now` - Check and execute automations as if the file has just been opened.
### Third party commands
Any command available in the current Obsidian context will be available to include in rules. When rules execute, only commands available in that context will run. This means you can use commands from Obsidian itself or any other plugin. Avoid automating commands that require input when they run as these parameters cannot be selected.
## Base files
When opening or updating a Base that uses the 'Rule Engine' view, rules with the 'base' or 'both' file handling will execute commands and apply templates.
### Table layout
Execute commands against results.

## Card layout
Using the card layout you can apply matching templates to each item automatically. Since base and rule filters can differ, you can apply different templates to each card.

### Settings
Configure the layout mode, toggle command execution and templates.

## Custom Views
Use the `HTML template` field in rules to render notes using custom HTML templates. If the `template` field is blank, no template will be used. The first matching template from the list of rules will be used.

**Custom views** allow you to:
- Create beautiful, custom HTML templates for specific notes
- Match files using powerful filter rules (file properties, frontmatter, tags, etc.)
- Transform data using filter chains (date formatting, text transformations, etc.)
- Render note content as markdown within your custom templates
- Render templates within base cards, to give you a customized overview.
Perfect for creating card views, dashboards, or any custom presentation of your notes!
### Usage
#### Getting Started
#### Basic Example
Let's create a simple view for movie notes. First, add a filter rule:
- **Property**: `file.folder`
- **Operator**: `contains`
- **Value**: `Movies`
Then, create a template like this:
```html
Year: {{year}}
Rating: {{rating}}/10
Published: {{date | date:"MMMM DD, YYYY"}}
Tags: {{file.tags | join:", " | wikilink}}
``` **Available Filters:** ##### Date Filters - `date:"FORMAT"` - Format a date (e.g., `date:"YYYY-MM-DD"`, `date:"MMMM DD, YYYY"`) - `date:"FORMAT":"INPUT_FORMAT"` - Parse and format a date with custom input format - `date_modify:"+1 year"` - Modify a date (e.g., `"+1 year"`, `"-2 months"`) ##### Text Transformation - `capitalize` - Capitalize first letter - `upper` - Convert to uppercase - `lower` - Convert to lowercase - `title` - Title case - `camel` - Convert to camelCase - `kebab` - Convert to kebab-case - `snake` - Convert to snake_case - `trim` - Remove leading/trailing whitespace - `replace:"search":"replace"` - Replace text (supports regex: `replace:"/pattern/flags":"replace"`) ##### Markdown Formatting - `wikilink:"alias"` - Convert to wikilink `[[value|alias]]` - `link:"text"` - Convert to markdown link `[text](value)` - `image:"alt"` - Convert to markdown image `` - `blockquote` - Convert each line to blockquote ##### Array Operations - `split:","` - Split string into array - `join:", "` - Join array into string - `first` - Get first element - `last` - Get last element - `slice:0:5` - Slice array or string - `count` - Get length of array or string ##### HTML Processing - `strip_tags` - Remove HTML tags ##### Math - `calc:"+10"` - Perform calculation (`+`, `-`, `*`, `/`, `^`) #### View Modes The plugin works in different view modes based on your settings: - **Reading Mode**: Custom views always work in reading mode (preview mode). - **Live Preview**: Optionally enable custom views in live preview mode via **Settings → Custom Views → Work in Live Preview**. - **Source Mode**: Custom views are disabled in pure source mode (true editor mode). #### Multiple Views You can create multiple custom views. The plugin will use the first matching view for each file. This allows you to have different templates for different types of notes. **Example:** - View 1: Movie cards (matches `file.folder contains "Movies"`) - View 2: Book cards (matches `file.folder contains "Books"`) - View 3: Project dashboards (matches `file.status is "active"`) #### Script Support You can include ` ``` > [!WARNING] > Scripts in templates are executed when the view is rendered. Be careful with scripts from untrusted sources. ### Examples #### Movie Card View **Filter Rule:** - `file.folder` contains `Movies` **Template:** ```htmlAuthor: {{author}}
Published: {{published | date:"YYYY"}}
Rating: {{rating}}/5 ⭐