マクロ内からの Twig マクロの不適切な使用を示す良い方法はありますか?
例えば:
{% macro _name_to_size(input) %}{% spaceless %}
{% set size %}
{% if input == 'small' %}20{% endif %}
{% if input == 'medium' %}40{% endif %}
{% if input == 'large' %}60{% endif %}
{% endset %}
{% if not size|trim|length %}
{# tell user that something is wrong #}
{% endif %}
{{ size }}
{% endspaceless %}{% endmacro %}
編集:
回答ありがとうございます。私はこのようなものになりました(ブラウザでこのようなものを見逃さない可能性があります):
{% macro error(message) %}
{% set notification %}
<div style="
background-color: {{ background }} !important;
display: block !important;
height: 100% !important;
left: 0 !important;
overflow: none !important;
position: fixed !important;
top: 0 !important;
width: 100% !important;
z-index: 1000 !important;
">
<div style="
background-color: {{ foreground }} !important;
color: white !important;
display: block !important;
font-size: 4em !important;
line-height: 1.6em !important;
left: 0 !important;
position: relative !important;
text-align: center !important;
top: 32% !important;
z-index: 1100 !important;
">{{ message }}</div>
</div>
{% endset %}
{{ notification }}
<script>
var messageDiv = document.createElement("div");
messageDiv.innerHTML = "{{ notification|e('js') }}";
document.body.appendChild(messageDiv);
</script>
{% endmacro %}