簡體   English   中英

將靜態路徑傳遞給包含的模板

[英]Passing static path to included template

是否可以將靜態路徑作為變量傳遞給包含的模板?

我需要在我的頁面上反復包含一個模板,但它總是帶有不同的徽標。

例如:

    {% with img={% static 'img/dashboards/belgium_flag.svg' %} %}
        {% include 'dashboards/charts/country_block.html' %}
    {% endwith %}

    {% with img={% static 'img/dashboards/netherlands_flag.svg' %} %}
        {% include 'dashboards/charts/country_block.html' %}
    {% endwith %}

這不起作用..

除了創建一個模型來支持每個 Country 實例的圖像屬性之外,還有什么解決方法嗎?

你可以用{% … as … %}子句做到這一點:

{% static 'img/dashboards/belgium_flag.svg' as img %}
{% include 'dashboards/charts/country_block.html' %}


{% static 'img/dashboards/netherlands_flag.svg' as img %}
{% include 'dashboards/charts/country_block.html' %}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM