{% extends "easydata/index.html" %} {% load url from future %} {% load i18n %} {% block menu-superior %}
  • {% trans "Home" %}
  • {% trans "Namespace" %}
  • {% trans "Visibility" %}
  • {% endblock %} {% block contenido-plantilla %}

    {% trans "Use in Django templates" %}

    {% blocktrans %}Using the URLs provided in the previous sections, the users can access to your information in RDF/XML, RDF/Ntriples and RDF/Turtle formats, but another way to publish your data, is including it into your html templates, using special tags that indicates the entities or properties, which represents your data.{% endblocktrans %}

    {% blocktrans %}The two available formats to do this, are microdata and rdfa. The EasyData/Django application, offers you multiple Django template tags, that can do this job easier for you. These template tags are differentiated by microdata and rdfa, and you only have to load the template tags in your Django templates using the following code:{% endblocktrans %}

    {% load easydata_microdata %}
    {% load easydata_rdfa %}

    {% blocktrans %}When you have loaded the template tags libraries, you can use the template tags to generate the html with the data of a instance and the tags which are mapped the model. The available template tags are the following:{% endblocktrans %}

    Microdata

    {% trans "To publish all the data of a model instance in Microdata format, you have the following template tags:" %}

    {% microdata_ul instance %}
    {% microdata_div_meta instance %}
    {% microdata_div_span instance %}

    {% trans "To publish data of a concrete field of the model instance you have the following template tags:" %}

    {% microdata_li_field instance "field_name" %}
    {% microdata_meta_field instance "field_name" %}
    {% microdata_span_field instance "field_name" %}

    {% blocktrans %}If you are going to publish a concrete field or fields of a model instance using microdata, you also have to use a specific template tag to include a html open tag with the instance information.{% endblocktrans %}

    {% microdata_open_tag "tag_name" %}

    {% trans "Example" %}

    {% blocktrans with nombre_model=example_model.nombre %}An example of the usage of the template tags showed before, if you want to publish in an unordered list, all the visible fields of a concrete instance of the model {{ nombre_model }} stored in a variable called var1, you have to put the following template tag in your Django template:{% endblocktrans %}

    {% microdata_ul var1 %}
    {% if microdata_code %}

    {% blocktrans %}The output that will generate the last tag, is the following:{% endblocktrans %}

    {{ microdata_code }}
    {% endif %}

    {% blocktrans with nombre_field=field.nombre %}On the other hand, if you want to publish only one field of the var1 instance, like the {{ nombre_field }} field, you have to do the following:{% endblocktrans %}

    {% microdata_li_field var1 "{{ field.nombre }}" %}

    RDFa

    {% trans "To publish all the data of a model instance in RDFa format, you have the following template tags:" %}

    {% rdfa_ul instance %}
    {% rdfa_div instance %}
    {% rdfa_div_span instance %}

    {% trans "To publish data of a concrete field of the model instance you have the following template tags:" %}

    {% rdfa_li_field instance "field_name" %}
    {% rdfa_div_field instance "field_name" %}
    {% rdfa_span_field instance "field_name" %}

    {% blocktrans %}If you are going to publish a concrete field or fields of a model instance using rdfa, you also have to use a specific template tag to include a html open tag with the instance information.{% endblocktrans %}

    {% rdfa_open_tag "tag_name" %}

    {% trans "Example" %}

    {% blocktrans with nombre_model=example_model.nombre %}An example of the usage of the template tags showed before, if you want to publish in an unordered list, all the visible fields of a concrete instance of the model {{ nombre_model }} stored in a variable called var1, you have to put the following template tag in your Django template:{% endblocktrans %}

    {% rdfa_div var1 %}
    {% if rdfa_code %}

    {% blocktrans %}The output that will generate the last tag, is the following:{% endblocktrans %}

    {{ rdfa_code }}
    {% endif %}

    {% blocktrans with nombre_field=field.nombre %}On the other hand, if you want to publish only one field of the var1 instance, like the {{ nombre_field }} field, you have to do the following:{% endblocktrans %}

    {% rdfa_div_field var1 "{{ field.nombre }}" %}

    {% trans "templates's directories" %}

    {% blocktrans %}Bellow you can see a list with all the directories where Django will search the templates, this means, that these are the directories where are located all the templates where you can use the template tags. The directories are the following:{% endblocktrans %}

    {% if list_dirs %} {% else %}

    {% trans "There isn't any template directory." %}

    {% endif %}

    {% blocktrans %}The templates also can be stored in the application directories, always on the folder called templates, and in the subfolder with the same name of the application. The paths of each application installed in the Django project are:{% endblocktrans %}

    {% if apps_dirs %} {% else %}

    {% trans "There isn't any application directory." %}

    {% endif %} {% endblock %}