[ckan-dev] Proper way to create a link

Adrià Mercader adria.mercader at okfn.org
Mon Nov 14 16:47:40 UTC 2016


Hi Lucia,

Following up on what Matthew said you can use the URL builder on any
route that you register on your own plugins:

<a href="{{ h.url_for('package_export', package_id=pkg.name,
file_format='datacite', extension='xml')}}" class="btn">

Also note that you should avoid using all c.xxx variables as this will
be deprecated in the future.

Hope this helps,

Adrià

On 12 November 2016 at 11:22, Matthew Fullerton
<matt.fullerton at gmail.com> wrote:
> Hi Lucia,
> I think something like this might be a minor improvement:
>
> {% set url = h.url_for(controller='package', action='package_read') %}
> <a href="{{url}}/export/datacite.xml"
> class="btn"><iclass="icon-file-text"></i>{{ _('Get DataCite XML')}}</a>
>
> Best,
> Matt
>
>
> On 11 November 2016 at 16:56, <lucia.espona at wsl.ch> wrote:
>>
>> Dear all,
>>
>> I am working on an extension that converts the CKAN metadata to a DataCite
>> XML (https://github.com/espona/ckanext-package_converter).
>>
>> In this first version the XML can be retrieved in two ways:
>> - Adding "/export/datacite.xml" to the package path, for example:
>> http://www.envidat.ch/dataset/10-16904-2/export/datacite.xml
>> - API call:
>> http://www.envidat.ch/api/action/package_export?id=10-16904-2&format=datacite
>>
>> Now I want to put a button in the package read page that downloads the
>> XML. I did a quick solution that works:
>>
>> <a href="/dataset/{{c.pkg_dict.get('name')}}/export/datacite.xml"
>> class="btn"><i class="icon-file-text"></i>{{ _('Get DataCite XML')}}</a>
>>
>>
>> Is there a better/cleaner way to do this?
>>
>> Thanks,
>> Lucia
>>
>>
>> _________________________________________________________
>> Dr. Lucia Espona Pernas
>>
>> Swiss Federal Institute for Forest, Snow and Landscape Research WSL
>> Hauptgebäaude Labortrakt (HL C21)
>> Zürcherstrasse 111
>> 8903 Birmensdorf
>> Switzerland
>>
>> +41 44 739 28 71 phone direct
>> +41 44 739 21 11 reception
>>
>> www.wsl.ch
>> _______________________________________________
>> ckan-dev mailing list
>> ckan-dev at lists.okfn.org
>> https://lists.okfn.org/mailman/listinfo/ckan-dev
>> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>>
>
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> https://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev
>



More information about the ckan-dev mailing list