MkCard
:fa-brands-github: Show source on GitHub
A card node, displaying an image, a button-like label and a hover caption.¶
Description
This node requires addtional CSS to work.
Bases: MkTemplate
__init__
¶
__init__(
title: str,
image: str,
*,
caption: str | None = None,
target: LinkableType | None = None,
size: int = CARD_DEFAULT_SIZE,
path_dark_mode: str | None = None,
**kwargs: Any
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Button text |
required |
image
|
str
|
Card image |
required |
caption
|
str | None
|
Image caption |
None
|
target
|
LinkableType | None
|
Link target. Can be a URL, an MkPage, or an MkNav |
None
|
size
|
int
|
Height/Width of the card |
CARD_DEFAULT_SIZE
|
path_dark_mode
|
str | None
|
Optional alternative image for dark mode |
None
|
kwargs
|
Any
|
keyword arguments passed to parent |
{}
|
| Name | Children | Inherits |
|---|---|---|
| MkTemplate mknodes.templatenodes.mktemplate Node representing a jinja template. |
graph TD
71538296["mkcard.MkCard"]
1289759389["mktemplate.MkTemplate"]
3160803176["rendercache.TemplateRenderMixin"]
2751680898["builtins.object"]
835538629["mkcontainer.MkContainer"]
1956333208["mkcontainer.MkContainerBase"]
1359323199["mknode.MkNode"]
1289759389 --> 71538296
3160803176 --> 1289759389
2751680898 --> 3160803176
835538629 --> 1289759389
1956333208 --> 835538629
1359323199 --> 1956333208
2751680898 --> 1359323199
/home/runner/work/mknodes/mknodes/src/mknodes/basenodes/mkcard/metadata.toml
[metadata]
icon = "mdi:square-medium"
status = "new"
name = "MkCard"
group = "image"
[[resources.css]]
filename = "grid.css"
[examples.with_link]
title = "With link"
jinja = """
{{ "Title" | MkCard("https://picsum.photos/300", target="https://phil65.github.io/mknodes/") }}
"""
[examples.with_caption]
title = "With caption"
jinja = """
{{ "Title" | MkCard("https://picsum.photos/300", caption="Caption") }}
"""
[examples.dark_mode_image]
title = "Separate dark mode image"
jinja = """
{{ "Title" | MkCard("https://picsum.photos/300", path_dark_mode="https://picsum.photos/200") }}
"""
[output.markdown]
template = """
{% set image = (node.image ~ "#only-light") if node.path_dark_mode else node.image %}
{% if node.target %}<a href="{{ node.target | get_url }}">
{% endif %}
<div class="card">
<div class="showcase-container">
<img src="{{ image }}" alt="{{ node.title }}" style="width:{{ node.size }}px,height:{{ node.size }}px">
{% if node.path_dark_mode %}<img src="{{ node.path_dark_mode }}#only-dark" alt="{{ node.title }}" style="width:{{ node.size }}px,height:{{ node.size }}px">
{% endif %}
{% if node.caption %}<div class="overlay">{{ node.caption }}</div>
{% endif %}
</div>
<p>
<button>{{ node.title }}</button>
</p>
</div>
{% if node.target %}</a>
{% endif %}
"""
Page info
Code for this page
Resources
Resources(css=[],
markdown_extensions={'admonition': {},
'pymdownx.details': {},
'pymdownx.highlight': {'anchor_linenums': True,
'line_spans': '__span',
'pygments_lang_class': True},
'pymdownx.superfences': {'custom_fences': [{'class': 'mermaid',
'format': <function fence_code_format at 0x703933662e50>,
'name': 'mermaid'}]},
'pymdownx.tabbed': {},
'tables': {}},
plugins=[Plugin('mkdocstrings')],
js=[],
assets=[Asset('grid_a2a710d.css')],
packages=[])