一键导入
bengal-add-filter
Adds a new Jinja/Kida filter to Bengal templates. Use when creating custom filters for formatting, filtering, or transforming template data.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Adds a new Jinja/Kida filter to Bengal templates. Use when creating custom filters for formatting, filtering, or transforming template data.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Adds a new MyST directive to Bengal. Use when creating custom content blocks (admonitions, cards, tabs), extending the rendering system, or adding a directive.
Migrates content from Markdown, Jekyll, Hugo, or other SSGs to Bengal. Use when converting a site, importing posts, or restructuring content.
Debugs Bengal build failures and errors. Use when builds fail, validation errors occur, or when fixing build errors.
Scaffolds a new Bengal static site with config, content structure, and theme. Use when creating a new site, starting a blog, or converting a project to Bengal.
Configures and uses taxonomy (tags, categories, indexes) in Bengal sites. Use when adding tags, categories, or querying content by section, author, or date.
Fixes common Bengal template errors and applies safe patterns. Use when templates fail with undefined variables, href vs path issues, baseurl, or config access.
| name | bengal-add-filter |
| description | Adds a new Jinja/Kida filter to Bengal templates. Use when creating custom filters for formatting, filtering, or transforming template data. |
Add a custom filter to Bengal's Kida template engine.
# python/filters.py
def currency(value: float, symbol: str = "$") -> str:
"""Format a number as currency."""
if value is None:
return f"{symbol}0.00"
return f"{symbol}{value:,.2f}"
Values from YAML/config can arrive as strings. Coerce numeric params:
from bengal.config.utils import coerce_int
def truncate_words(value: str, length: int = 50, suffix: str = "...") -> str:
length = coerce_int(length, 50) # Coerce from YAML string
if not value:
return ""
words = value.split()
if len(words) <= length:
return value
return " ".join(words[:length]) + suffix
Uses internal API (may change; plugin API planned for v0.4.0):
# python/filter_registration.py
def register_filters(site) -> None:
if hasattr(site, '_template_engine') and site._template_engine:
env = site._template_engine._env
env.add_filter("currency", currency)
env.add_filter("truncate_words", truncate_words)
Use a custom build script:
# build.py
from pathlib import Path
from bengal.core import Site
from bengal.orchestration.build import BuildOptions
from python.filter_registration import register_filters
site = Site.from_config(Path("."))
register_filters(site)
site.build(BuildOptions())
{{ 1234.56 | currency }}
{{ 1234.56 | currency("€") }}
{{ page.content | truncate_words(20) }}
coerce_int(value, default) at filter entrySee references/add-filter-guide.md for build script options and @template_safe for error-prone functions.