Open carljoseph opened 7 months ago
Figured it out. {{extra}}
works for me in my template.
After a bit of tinkering and ChatGpt, what worked for me was to use regex to parse through the Extra
field.
Take the following file as an example:
To extract the Read_Status
, I apply the following set of scripts:
{%- set input_string = extra | string | replace("\n", " ")%}
{%- set regex_read_status = r/Read_Status:\s*(.*?)(?=\s+\w+\s*:\s*|$)/g %}
{%- set matches_read_status = regex_read_status.exec(input_string) %}
{%- if matches_read_status and matches_read_status[1] %}
{%- set read_status =matches_read_status[1] %}
{{read_status}}
{%- endif %}
The output is:
Read
For more info on the regex applied, check out the following link: https://regex101.com/r/vB41So/2
For my use-case, I removed all spacing and line breaks and put a less readable version into my properties/frontmatter. The result is that when a template is applied the relevant field/s are updated.
For example (this is the same as the above template, without the additional spacing)
read_status: {% set input_string = extra | string | replace("\n", " ")%}{% set regex_read_status = r/Read_Status:\s*(.*?)(?=\s+\w+\s*:\s*|$)/g %}{% set matches_read_status = regex_read_status.exec(input_string) %}{%- if matches_read_status and matches_read_status[1] %} {%- set read_status =matches_read_status[1] %}{{read_status}}{%- endif %}
In the template, the nunjucks templating format might appear as an error, but the processed result works fine.
Hi BBT, the
extras
field is exported as anannotation
. I want to include this text in my Obsidian template, but I can't figure out what variable to use?