{# Renders a single resource with icons and view links. res - A resource dict to render pkg - A package dict that the resource belongs to can_edit - Whether the user is allowed to edit the resource url_is_edit - Whether the link to the resource should be to editing it (set to False to make the link view the resource) url - URL of the resource details page(resource edit/read depending on url_is_edit, by default). Example: {% snippet "package/snippets/resource_item.html", res=resource, pkg=pkg, can_edit=True, url_is_edit=False %} #} {% set url_action = pkg.type ~ ('_resource.edit' if url_is_edit and can_edit else '_resource.read') %} {% set url = url or h.url_for(url_action, id=pkg.name, resource_id=res.id) %}
  • {% block resource_item_title %} {% set name_or_id = res.name or res.id %} {{ h.resource_display_name(res) | truncate(50) }} {{ h.get_translated(res, 'format') }} {% endblock %} {% block resource_item_description %}

    {% if res.description %} {{ h.markdown_extract(h.get_translated(res, 'description'), extract_length=80) }} {% endif %}

    {% endblock %}
    {% block resource_item_explore %} {% if not url_is_edit %} {%- call ui.util.call(ui.dropdown, title=ui.icon("share") ~ _('Explore')) -%} {% block resource_item_explore_links %} {% block explore_view %} {%- call ui.util.call(ui.dropdown_item, href=url) -%} {% if res.has_views %} {{ ui.icon("chart-bar") }} {{ _('Preview') }} {% else %} {{ ui.icon("info-circle") }} {{ _('More information') }} {% endif %} {%- endcall %} {% endblock explore_view %} {% if res.url and h.is_url(res.url) %} {%- call ui.util.call(ui.dropdown_item, href=res.url, blank=true, class="dropdown-item resource-url-analytics") -%} {% if res.has_views or res.url_type == 'upload' %} {{ ui.icon("arrow-circle-down") }} {{ _('Download') }} {% else %} {{ ui.icon("external-link") }} {{ _('Go to resource') }} {% endif %} {%- endcall %} {% endif %} {% if can_edit %} {{ ui.dropdown_item(ui.icon("pencil") ~' '~ _('Edit resource'), href=h.url_for(pkg.type ~ '_resource.edit', id=pkg.name, resource_id=res.id)) }} {% block resource_item_explore_inner scoped %}{% endblock %} {{ ui.dropdown_item(ui.icon("chart-bar") ~' '~ _('Views'), href=h.url_for(pkg.type ~ '_resource.views', id=pkg.name, resource_id=res.id)) }} {% endif %} {% endblock %} {%- endcall %} {% endif %} {% endblock %}