Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2015-05-18 19:56:13

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

template inheritance

I’ve written a plugin that gives you <txp:rvm_inherit> and <txp:rvm_block> tags to create template inheritance similar to how Mako does it (for both pages and forms, mixed if you desire). Would it be interesting to release this (I’d have to write documentation) or is this problem better solved using current TXP tags or perhaps there’s already a plugin that does this (although I couldn’t find one)?

Offline

#2 2015-05-18 21:54:28

sacripant
Plugin Author
From: Rhône — France
Registered: 2008-06-01
Posts: 479
Website

Re: template inheritance

Very interesting.

I’m working right now on a platform under django / python. and I discover the templating logic by inheritance. in some cases it’s more interesting that templating by inclusion.

But do your plugin will be compatible with the context logique of textpattern ?

Offline

#3 2015-05-18 22:13:55

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: template inheritance

sacripant wrote #290888:

But do your plugin will be compatible with the context logique of textpattern?

Do you mean the <txp:if_... stuff? Yes, should be compatible with that.

Offline

#4 2015-05-19 00:35:10

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: template inheritance

Hi Ruud,

One of the things I love about Textpattern (versus, say, WP) is its code readability. Does what you propose still go along with that?

I use combinations of <txp:output_form />, <txp:cbe_output_form />, txp:adi_if_content & <txp:atb_if_form />. These give me the ability to use/reuse blocks of code, pass parameters to blocks of code and conditional execution of code.

Could you explain what your plugin brings to the party – maybe for the less-quick of mind, an example of how your plugin would work?

Offline

#5 2015-05-19 08:18:01

sacripant
Plugin Author
From: Rhône — France
Registered: 2008-06-01
Posts: 479
Website

Re: template inheritance

Do you mean the <txp:if_... stuff? Yes, should be compatible with that.

Yes, but what about logic ? It will be difficult for me to explain in English… I try

Textpattern start his template by a “page (depend to section pref)” and after, include chunk of code (form) that depend of context and ‘if’ tags.
globally, We start by site layout (page) and include particular content (forms).

for exemple with a article section :

Start to Page template -> (if my section) Include section Form -> (if individual-article) include article form.

In inheritance template system, you start by a particular template page, defining by a particular context.
With the same exemple : a section article is defining from my-section-article form.

Start to My-section-article-form -> (that extend) My-section-form -> (that extend) my-site-global-layout

it’s difficult for me to understand how a inheritance templating system can be interesting in a system where all context start by analyzing the same page (a page template).

Offline

#6 2015-05-19 08:57:48

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: template inheritance

Main template (default):

<html>
    <body>
        <div class="header">
            <txp:rvm_block name="header"/>
        </div>

        <txp:rvm_block name="body">

        <div class="footer">
            <txp:rvm_block name="footer">
                this is the footer
            </txp:rvm_block>
        </div>
    </body>
</html>

Inherited template (child):

<txp:rvm_inherit name="default">

  <txp:rvm_block name="header">
    this is some header content
  </txp:rvm_block>

  <txp:rvm_block name="body">
    this is the body content.
  </txp:rvm_block>

</txp:rvm_inherit>

If you assign the inherited “child” page to a section, the output would be:

<html>
    <body>
        <div class="header">
            this is some header content
        </div>

        this is the body content.

        <div class="footer">
            this is the footer
        </div>
    </body>
</html>

You don’t have to stop with just one layer of inheritance, you can chain them. For example, a “grandchild” template:

<txp:rvm_inherit name="child">

  <txp:rvm_block name="footer">
    copyright 2015
  </txp:rvm_block>

  <txp:rvm_block name="body">
    And here's some other body content.
  </txp:rvm_block>

</txp:rvm_inherit>

Which would give you:

<html>
    <body>
        <div class="header">
            this is some header content
        </div>

        And here's some other body content.

        <div class="footer">
            copyright 2015
        </div>
    </body>
</html>

The <txp:rvm_inherit> tag has 2 attributes: page and form. So you can inherit a page or a form. In an inheritance chain you can mix page and form.

The <txp:rvm_block> tag has 3 attributes: name, child, parent. The latter two are by default not set, but if you set them to 1, you get the effect described here (instead of ${next.body()}, read <txp:rvm_block name="body" child="1"/> and here (instead of ${parent.toolbar()}, read <txp:rvm_block name="toolbar" parent="1"/>

Offline

#7 2015-05-19 09:26:46

sacripant
Plugin Author
From: Rhône — France
Registered: 2008-06-01
Posts: 479
Website

Re: template inheritance

Also, your system is limited only for section context (only start from a page).
Apparently, it’s not possible to start a inheritage template form other context (author, individual artcile, categorie; lists, etc.).
it may already be useful in some cases.

Offline

#8 2015-05-19 09:31:52

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: template inheritance

sacripant wrote #290905:

Also, your system is limited only for section context (only start from a page).

No, it is not. You can do this if you want:

<html>
<body>
something here
<txp:rvm_inherit form="formname">
  <txp:rvm_block name="heading">
    My heading
  </txp:rvm_block>
</txp:rvm_inherit>
something else

And in an inherited page template, where the original page includes forms, there can be <txp:rvm_block> tags in the included forms.

Offline

#9 2015-05-19 10:56:38

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: template inheritance

Ruud, would you liken it to Twig’s template inheritance?

Offline

#10 2015-05-19 11:12:32

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: template inheritance

wet wrote #290918:

Ruud, would you liken it to Twig’s template inheritance?

Yes.

Offline

#11 2015-05-19 11:27:59

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

Re: template inheritance

Ok, Although it looks very interesting, I know that I am not getting this as I can not see the difference between it and the txp forms.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#12 2015-05-19 12:12:56

sacripant
Plugin Author
From: Rhône — France
Registered: 2008-06-01
Posts: 479
Website

Re: template inheritance

Ai aiai, i think my brain is broken.

I need a code translate.

When you call a author context (your-site/index.php?author=author+Name) and you want use a inheritance logique template.
with Jinja (or Twig) you can have something like this :
You map [Author context = start template analysing from author-list.html]

author-list.html :

{% extends "base.html" %}

{% block head-title %}
   page title for author list page
{% endblock %}

{% block main %}
  <h1><txp:author /></h1>
  <txp:article form="author-list" limit="5" />
{% endblock %}

base.html :

<html>
  <head>
    some code
    <title>
    {% block head-title %}{% endblock %}
    </title>
     some code   
  </head>
  <body>
    some code
    <main>
    {% block main %}{% endblock %}
    </main>
    some code
  </body>
</html>

Ruud, can you please translate this exemple with your system ?

Offline

Board footer

Powered by FluxBB