1
votes

I have read the 'custom-editing-interfaces-for-structblock' section of documentation. Then I have written:

 settings = StructBlock([
            ('width', blocks.CharBlock(required=False, max_length=20 ) ),
            ('background_color', blocks.CharBlock(max_length=10, required=False))
        ],  form_template = 'personal_web/admin_blocks/section_settings.html' )

I have copied the code in wagtail/admin/templates/wagtailadmin/block_forms/struct.html to my custom struct template for better customizing.

--- my section_settings.html ---

<div class="{{ classname }}">
    {% if help_text %}
        <div class="object-help help">{{ help_text }}</div>
    {% endif %}

    <ul class="fields">
        {% for child in children.values %}
            <li{% if child.block.required %} class="required"{% endif %}>
                {% if child.block.label %}
                    <label{% if child.id_for_label %} for="{{ child.id_for_label }}"{% endif %}>{{ child.block.label }}:</label>
                {% endif %}
                {{ child.render_form }}
            </li>
        {% endfor %}
    </ul>
</div>

On the admin there is an error:

'builtin_function_or_method' object is not iterable... In template /Users/burakk/BurakWorks/Web/VIRTUAL_ENVIRONMENTS/python3.6.1_dj_1_11/lib/python3.6/site-packages/wagtail/wagtailadmin/templates/wagtailadmin/block_forms/sequence_member.html, error at line 23

By the way I am using jinja as template renderer, django 1.11.6, python 3.6

I checked to see if this was an jinja2 issue I have changed the children.values properties children.values() etc...

Now on the admin I see all the elements as 'html string' not the actual input fields...

Thanks

1
Is your section_settings.html template completely identical to wagtail/admin/templates/wagtailadmin/block_forms/struct.html? If not, please post your template code. Note that you cannot use jinja2 for this template - the Wagtail admin always uses the Django template engine for its templates, regardless of what you're using on your site frontend. - gasman
I have edited my post with the section_settings.html code. I had to change the children.values -- to children.values() because of the error... But my template is in my apps folder... I am not overriding the wagtail struct.html template with wagtail template path structure. Can this be the reason? - ratata
"Can this be the reason" - well, there's an easy way to find out! Remove it, and see if the problem still happens. - gasman
no that is not the reason - ratata
If I emptied the section_settings.html and write a 'div' for example, on the admin it renders as html string not as actual html elements? - ratata

1 Answers

1
votes

I think this might be happening because your section_settings.html template is inside the location normally used for jinja2 templates - probably some_app/jinja2/personal_web/admin_blocks/section_settings.html (if you're using the configuration shown at http://docs.wagtail.io/en/v1.13.1/advanced_topics/jinja2.html) - and ends up being interpreted as a Jinja2 template. Mixing Jinja2 and Django templates in this way is untested, and likely to fail in unpredictable ways (such as the HTML being double-escaped, as you're seeing).

Try moving it to some_app/templates/personal_web/admin_blocks/section_settings.html, with the template changed back to Django syntax (children.values() changed back to children.values, etc).