-
I am completely new to using macros so this may be a simple fix. I am getting the following error:
This is my macro:
I am referencing in my code like this:
I am assuming the that error is in the macro based off the error and not how I am importing/using it in my template. Any help would be appreciated. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Close, but I think you have too many ---
title: 11ty-3036
injuries:
- data: { impact: "Low" }
- data: { impact: "Medium" }
- data: { impact: "High" }
- data: { impact: "Extreme" }
---
{% macro impactColor(injuryLevel) %}
{%- if injuryLevel == "Low" -%}
<span class="injury-impact text-xs text-gray-500 dark:text-gray-400" style="color: green;">
{%- elif injuryLevel == "Medium" -%}
<span class="injury-impact text-xs text-gray-500 dark:text-gray-400" style="color: yellow;">
{%- elif injuryLevel == "High" -%}
<span class="injury-impact text-xs text-gray-500 dark:text-gray-400" style="color: red;">
{%- endif -%}
{{ injuryLevel }}
</span>
{% endmacro %}
{# {% from "impactColor.njk" import impactColor %} #}
{% for injury in injuries %}
<p class="text-xs text-gray-500 dark:text-gray-400">
<strong>Impact Level:</strong>
{{ impactColor(injuryLevel = injury.data.impact) }}
</p>
{% endfor %} OUTPUT<p class="text-xs text-gray-500 dark:text-gray-400">
<strong>Impact Level:</strong>
<span class="injury-impact text-xs text-gray-500 dark:text-gray-400" style="color: green;">Low</span>
</p>
<p class="text-xs text-gray-500 dark:text-gray-400">
<strong>Impact Level:</strong>
<span class="injury-impact text-xs text-gray-500 dark:text-gray-400" style="color: yellow;">Medium</span>
</p>
<p class="text-xs text-gray-500 dark:text-gray-400">
<strong>Impact Level:</strong>
<span class="injury-impact text-xs text-gray-500 dark:text-gray-400" style="color: red;">High</span>
</p>
<p class="text-xs text-gray-500 dark:text-gray-400">
<strong>Impact Level:</strong>
Extreme
</span>
</p> (Note that it sort of broke when I passed an invalid |
Beta Was this translation helpful? Give feedback.
Or if you want an alternate idea which uses a color map and tailwind colors: