Skip to content

Conversation

ggcatu
Copy link
Contributor

@ggcatu ggcatu commented Aug 10, 2017

Fixes #

Proposed fixes:

Add blocks in datastore plugin templates, dictionary.html and resource_read.html so we can easily customize and expand

@ggcatu
Copy link
Contributor Author

ggcatu commented Aug 11, 2017

Why can't this be done?

      {% for f in ddict %}
            <tr>
 +            {% block resource_data_dictionary_items %}
              <td>{{ f.id }}</td>
              <td>{{ f.type }}</td>
              <td>{{ h.get_translated(f.get('info', {}), 'label') }}</td>
              <td>{{ h.render_markdown(
                h.get_translated(f.get('info', {}), 'notes')) }}</td>
 +            {% endblock %}
            </tr>
          {% endfor %}

You get f not defined

Please keep in mind that it is not possible to set variables inside a block and have them show up outside of it. This also applies to loop

But the next block is inside

This build pass the tests, but it's actually not printing anything, ddict inside the block is empty.

@ggcatu
Copy link
Contributor Author

ggcatu commented Aug 11, 2017

So, you cannot declare a variable inside a block, and expect to use it inside an inner one.

Don't know what's the workaround, but as for now should be working.

Any tip appreciated.

@wardi
Copy link
Contributor

wardi commented Aug 17, 2017

A common pattern in the ckan templates is to use a snippet for repeated blocks like this, that makes it easy for an extension to override, and all variables are passed in.

We have a separate problem that snippets aren't being cached and slow down rendering, but that can be fixed in another PR.

@ggcatu
Copy link
Contributor Author

ggcatu commented Aug 18, 2017

@wardi like this?

@@ -0,0 +1,7 @@
<tr>
<td>sdfasdf {{ f.id }}</td>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sdfasdf?

{% block resource_data_dictionary_data %}
{% set ddict=h.datastore_dictionary(res.id) %}
{% for f in ddict %}
{% snippet "package/snippets/dictionary_table.html", f=f, h=h %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to pass h. please use a name like 'field' instead of 'f' since inside the snippet it's no longer clear from context what it contains.

{{ form.markdown('info__' ~ loop.index ~ '__notes',
label=_('Description'), id='field-d' ~ loop.index ~ 'notes',
value=f.get('info', {}).get('notes', '')) }}
{% snippet "datastore/snippets/dictionary_form.html", f=f, position=loop.index, form=form %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please pass f as field, no need to pass form (the snippet can import it itself)

@ggcatu
Copy link
Contributor Author

ggcatu commented Aug 25, 2017

Should "No newline at end of file" be fixed?

{% block resource_data_dictionary_data %}
{% set dict=h.datastore_dictionary(res.id) %}
{% for field in dict %}
{% snippet "package/snippets/dictionary_table.html", field=field, h=h %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for h=h here

@wardi wardi merged commit 177143f into ckan:master Sep 1, 2017
@tino097
Copy link
Member

tino097 commented Sep 22, 2017

@amercader @wardi i think this can be backported too

@amercader
Copy link
Member

Unless it's fixing an actual bug, I wouldn't backport changes in the template structure, as we might break extensions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants