Re: [Zotonic-Usr] How admin section, templates and modules works together questions.

68 views
Skip to first unread message

Andreas Stenius

unread,
Aug 31, 2012, 2:56:10 PM8/31/12
to zotoni...@googlegroups.com
templates is quite different from resources (pages).

A resource holds data, but no presentation. The template is used to
layout and present the resource data.
Somewhat like html vs. css for separating the data from the
presentation (design).

> 1. If I create this page as a template, can I edit the template using the
> editor from the admin section e.g. to correct any typos or the whole copy or
> header without opening the template file?

There is currently no way to edit the templates via the web GUI. The
idea is that the templates are rarely changed,
after they've been developed; but resources are created and edited
continuously.

> 2. Can I create the page using the HTML editor from the admin section and
> somehow include the call to the module to include the dynamic table?

I would have the design in a template, and get the data from pages. So
you create the content in the admin.
No need to call a custom module.

> 3. Say I would like to have a few configuration options for generating the
> table (e.g. number of rows for the sake of an example). Can I somehow
> include such configuration option in the admin section of the site once the
> module to generate the table has been enabled?

There's a config model you can use from your template if you need
configuration per site: http://zotonic.com/documentation/719/m-config

> 4. Sometimes a page is build using only a template, but I can still edit the
> page in the admin section (e.g. the homepage of the blog exemplary site).
> The HTML editor doesn't show any text, it's empty. What is the purpose of
> showing that editor for a page that is shown only from a template?
>

It depends on the what the template does with the content of the page.
In the case above,
maybe the content isn't used at all. But it could be to put a
temporary notice on the front page, for instance.

I'm sure this didn't answer all your questions, but hopefully
triggered some new ones... :)

Amiramix

unread,
Aug 31, 2012, 3:40:48 PM8/31/12
to zotoni...@googlegroups.com
Andreas, many thanks for your answers. Yes, we are looking at the system from different perspectives so I would love to clarify if I understood your point properly. For the sake of an example say that the page looks like this:

section header-copy-1 (some header + some copy)
A dynamic table
section header-copy-2 (another header + another copy)
A dynamic graph

I would like to generate the table and the graph using custom modules (say the data is coming from an external server which I need to consume and process).

According to your description I can create two page resources for section header-copy-1 and header-copy-2 using the web GUI and then one template to layout both sections, the table and the graph on a web page presented to the user. If I edit either page resource (header-copy-1 or header-copy-2) then the web page will be updated automatically when the template pulls them from the database next time the web page is requested. Is my thinking correct?

If yes, then is there any easy way of referencing a particular page resource created using the web GUI in a template? I understand I could use m.rsc[id] but the id is not shown by the web GUI (there is an integer in the url and a unique name assigned in the GUI but I am not sure if either can be reliably used to reference a page resource).

Andreas Stenius

unread,
Sep 1, 2012, 7:36:54 AM9/1/12
to zotoni...@googlegroups.com
2012/8/31 Amiramix <li...@gjunka.com>:
> Andreas, many thanks for your answers. Yes, we are looking at the system
> from different perspectives so I would love to clarify if I understood your
> point properly. For the sake of an example say that the page looks like
> this:
>
> section header-copy-1 (some header + some copy)
> A dynamic table
> section header-copy-2 (another header + another copy)
> A dynamic graph

OK

> I would like to generate the table and the graph using custom modules (say
> the data is coming from an external server which I need to consume and
> process).

Sounds right.

> According to your description I can create two page resources for section
> header-copy-1 and header-copy-2 using the web GUI and then one template to
> layout both sections, the table and the graph on a web page presented to the
> user. If I edit either page resource (header-copy-1 or header-copy-2) then
> the web page will be updated automatically when the template pulls them from
> the database next time the web page is requested. Is my thinking correct?

Yes (but there's room for improvements, in case you run on 0.9-dev,
which I'll present further down)

> If yes, then is there any easy way of referencing a particular page resource
> created using the web GUI in a template? I understand I could use m.rsc[id]
> but the id is not shown by the web GUI (there is an integer in the url and a
> unique name assigned in the GUI but I am not sure if either can be reliably
> used to reference a page resource).

The number you see in the url, is the unique id for the resource, and
can be used reliably.
But there is a better way. By giving the resource a unique name, you
can then reference that
name in your templates (and as such, replace which resource is being
used at a later time by
moving/replacing the resource with that name).

To get the resource of a given name in your template, use:
m.rsc.my_name.some_property

As mentioned earlier, if you're on 0.9-dev, you can stick with a
single resource (page) for all sections
of your page. Marc recently added support for having (optionally
named) sections to a resource.
So, that way you can name your sections and pull your corresponding
section from the resource
in the right place in the template.

On 0.8, you're probably best of using a set of resources as you suggested.

//Andreas

Ps.
If you're new to modules (and models) I'd recommend a quick glance
introducing those topics in my "Writing your own Zotonic module"
series: http://blog.astekk.se/en/by_keyword/318/zotonic
It's in Part IV that models are introduced, and things begin to be a
bit more interesting. Unfortunately I've only written four parts... to
be continued (any year now).

Amiramix

unread,
Sep 1, 2012, 10:10:03 AM9/1/12
to zotoni...@googlegroups.com
Many thanks Andreas, that's all very useful information, especially the tutorial on creating new modules. I will be trying it today. But I'd like to ask one more thing as it doesn't seem to be documented. How can I mark a section in the web GUI so that it can be later referenced in the template?

Andreas Stenius

unread,
Sep 1, 2012, 1:28:36 PM9/1/12
to zotoni...@googlegroups.com
I don't think there is a standard way to do this, apart from using the
new sections added in 0.9-dev.

There are however some filters that can parse the html body of a
resource, which you then can dissect as you like.

Search the archives for DOM, HTML parser, or the like from Maas-Marten
Zeeman (apologies if I spelled your name wrong, Maas, as I'm too lazy
to look it up).

Don't remember if it was published, or only something that Maas was
working on, though.

2012/9/1 Amiramix <li...@gjunka.com>:

Amiramix

unread,
Sep 1, 2012, 2:35:05 PM9/1/12
to zotoni...@googlegroups.com
Andreas, how do I use the new sections added by Marc in 0.9-dev? Is it documented anywhere?

Andreas Stenius

unread,
Sep 1, 2012, 3:30:33 PM9/1/12
to zotoni...@googlegroups.com
Not that I know of (apart from this intro:
https://groups.google.com/d/topic/zotonic-developers/JpQ7kTKA28Y/discussion
)

2012/9/1 Amiramix <li...@gjunka.com>:

Amiramix

unread,
Sep 1, 2012, 4:07:20 PM9/1/12
to zotoni...@googlegroups.com
Ah, I didn't even notice the add block button before. So this is what is it for. Many thanks, that's exactly what I was looking for!
Reply all
Reply to author
Forward
0 new messages