Content Blocks

35 views
Skip to first unread message

Seann Aswell

unread,
Jan 11, 2024, 3:51:21 PMJan 11
to Zotonic developers
Another question...

In the admin there is the option of adding content blocks to resources, which seems really handy. 

How can I address the additional blocks in HTML? I am obviously missing something, as I do not see any properties defined in m_rsc regarding content blocks.

Currently on a few webpages, I have added multiple resources and called {id.body} multiple times in HTML to achieve the same affect...

Marc Worrell

unread,
Jan 13, 2024, 7:14:14 AMJan 13
to zotonic-d...@googlegroups.com
--

---
You received this message because you are subscribed to the Google Groups "Zotonic developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotonic-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zotonic-developers/971f861c-3850-4fe1-b1fc-815c4d6ba794n%40googlegroups.com.

Seann Aswell

unread,
Jan 14, 2024, 3:32:29 AMJan 14
to Zotonic developers
Very interesting...

So, if I add a Header block called "header1" and a Text block called "text1", are those fields directly addressable using something like "blk.name"?

For instance, I see in "_block_view_page_inline.tpl":

    {% for blk in id.blocks %}
        {% if blk.type == "header" %}

Is there a blk.name variable associated with the name of the block added? If so, can you recommend how to address each block via name directly?

What I am hoping to achieve is to have one resource with multiple Header and Text blocks, but I need to address each one directly, to display in a particular place in the HTML layout. However, I am unsure how to display a specific blk by name, rather than listing them all as the above example shows.

The flexibility you built into the system is impressive, but I am still learning my way around...

Marc Worrell

unread,
Jan 14, 2024, 5:23:27 AMJan 14
to zotonic-d...@googlegroups.com
You can use:

id.blocks.name.title

Where “title” is a property of the block. And name is the name of your block.

If your name includes spaces:

id.blocks[“name of block”].title

Cheers, Marc



Sent from my iPhone

On 14 Jan 2024, at 09:32, 'Seann Aswell' via Zotonic developers <zotonic-d...@googlegroups.com> wrote:



Seann Aswell

unread,
Jan 15, 2024, 3:32:51 AMJan 15
to Zotonic developers
When I use the following, without .title on the end, it works.

{% for blk in id.blocks.name %}
        {% include "blocks/_block_view_text.tpl" %}
{% endfor %}

If there is a better way, let me know. 

Else, thanks again. Much appreciated.

Marc Worrell

unread,
Jan 15, 2024, 3:42:45 AMJan 15
to 'Seann Aswell' via Zotonic developers
Hi Seann,

I would expect it to be:

{% for blk in id.blocks %}
        {% include "blocks/_block_view_text.tpl" %}
{% endfor %}

But that renders only blocks of the type ’text’.

The suffix _text is the type of the block, we added different templates for the different types.
You can see in the mod_survey how we use those to render the different questions.

That is also why we add the type of the block when including using the “_blocks.tpl”:

{% for blk in m.rsc[id].blocks %}
    {% optional include ["blocks/_block_view_",blk.type,".tpl"]|join blk=blk id=id %}
{% endfor %}

(id.blocks is shorthand for m.rsc[id].blocks)

Cheers, Marc


Seann Aswell

unread,
Jan 15, 2024, 4:38:17 AMJan 15
to Zotonic developers
{% for blk in m.rsc[id].blocks %}
    {% optional include ["blocks/_block_view_",blk.type,".tpl"]|join blk=blk id=id %}
{% endfor %}
Understand, thanks for the correct format. 

Thanks again,
Seann
Reply all
Reply to author
Forward
0 new messages