Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-05-03 05:04:20

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

<txp:extends />, <txp:block></txp:block>, expanding templates

Hi all,

I come with this idea borrowed from Django templates (who probably took it from other templating system).
I don’t know yet if it is a good idea, or if is it in the spirit and style of TxP logic, but let see if something comes up (althought, it could be an idea, similar to this new upcoming TxP features).

Summary: the idea is to expand templates (and predefined blocks in those templates) from other templates (the ones finally asigned to render a section). This may be over-killing right now, but it could coming handy in a future, if TxP supports subsections (and so, page templates could be asigned to subsections, as today are asigned to sections). It’s like the inversion of an include (<txp:output_form />).

Expanding templates: <txp:extends /> and <txp:block></txp:block>:

Single tag: <txp:extends template="page_template_name" />
Container (block) tag: <txp:block name="block_name"></txp:block>

This tags is used at top of a page template, and it has an template attribute and its possibles values are the names of any page template.
“To expand a templates” means to fill some predefined blocks in the expanded template with the chunks of code (also blocks) in the expander template.
Blocks are created with

Example:

Expanded template: skeleton

 <txp:output_form form="header">

    <div id="content">
        <div id="primary">
             <txp:block name="primary"><!-- this creates a block than then can be filled in, when expanding this template)
             </txp:block>
        </div><!-- #primary -->
        <div id="secondary">
             <txp:block name="secondary">
             </txp:block>
        </div><!-- #secondary -->
    </div><!-- #content -->

<txp:output_form form="footer">

Expandor template: articles

<txp:extends template="skeleton"> <!-- this indicates: expand **skeleton** template -->

<txp:block name="primary">  <!-- the content of this block fills in the block "primary" on skeleton template -->
    ...more HTML and TxP tags... like
    <div class="article-list">
         <txp:article />
     </div>
</txp:block>

<txp:block name="secondary">  <!-- the content of this block fills in the block "secondary" on skeleton template -->
    ...more HTML and TxP tags... like
    <div class="recent_articles">
         <txp:recent_articles />
     </div>
</txp:block>

So, when creating the articles section, you assign the articles page template to it, and that template will expand the skeleton.

As said, this may be too much (or maybe not) for current TxP.
One advantage is on maintenance, because you can have one skeleton and then you can expand it.
If someday we have subsections, a template can be assigned to the subsection, and putting the <txp:extends /> tag on the top of that template, you can choose to expand the section template (that is, the template assigned to the section to which the subsection belongs), or another template, or directly the skeleton template.
This way, subsections templates aren’t “attached” to their section templates.

That’s all. Thanks.

edit: changed <txp:expand /> to <txp:extends /> (that’s what I wanted to use)

Last edited by maniqui (2008-05-03 07:10:43)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#2 2008-05-03 06:01:23

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: <txp:extends />, <txp:block></txp:block>, expanding templates

You can use forms to do the same. In example if I use TXP, I use “templates” aka pages only to call forms, so I already have the seceloton. Those forms are just blogs and if I really need different blocks, I just leave them out or I use conditionals.

In example:

<txp:output_form form="x-head" />
<txp:output_form form="x-middle" />
<txp:output_form form="x-left" />
<txp:if_section name="gallery,,maps"><txp:else />
	<txp:output_form form="x-right" />
</txp:if_section>
<txp:output_form form="x-navigation" />
<txp:output_form form="x-bottom" />

Probably someone asks, why the example navigation block is at the bottom of the page, answer: SEO.

Last edited by Gocom (2008-05-03 06:05:33)

Offline

#3 2008-05-03 07:08:50

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: <txp:extends />, <txp:block></txp:block>, expanding templates

Hi Gocom,

Sorry for using the term “templates”, I wanted to say “pages” (or page templates), but my head was thinking in Django.
Of course I know the method you suggest (if I’ve been here more than 3 or 4 years and I don’t know about it, then I would really have to think about my capabilities).
But I’m not sure if it is exactly the same (at least, in Django, to include a template is not the same as to expand a template), although you are clever than me, so it may be the same.

First, I forgot something important about the hypothetical <txp:block></txp:block> tag. It also would need to support something like this:

skeleton page:

(...)
<txp:block name="css">
       <link css_a />
       <link css_b />
       <link css_c />
</txp:block>
(...)

article page: (expandor page template)

<txp:extends page="skeleton" />

<txp:block name="css" super="append" >  <!-- this will append the content to the filled in block in skeleton -->
     <link css4 />
     <link css5 />
</txp:block>

attribute super means to extend the block, prepending/appending the content to the block on skeleton. If super isn’t passed, then the content is overwritten/overridden.

The “One template with many if_section to rule them all” approach… I’ve been there… and after some long time using it, I switched to a one-template-per-section (or, at most, one-template-used-by-a-few-sections) approach and for me is cleaner, less brain needed, more flexibility .(at least for me) and I feel it more comfortably.

Mixed this approach with the expand approach will let me set a general skeleton (most sites use just one common skeleton), and then, in inner templates (section/subsection templates), just write the code for the blocks I want to fill in.

So, refining the examples from the first post:

Expanded template: skeleton
 <txp:output_form form="header">

    <div id="content">
        <div id="primary">
             <txp:block name="primary">
                   <txp:article status="sticky limit="1" />
             </txp:block>
        </div><!-- #primary -->
        <div id="secondary">
             <txp:block name="secondary">
                     <txp:output_form name="about-site" />
                     <txp:recent_comment />
             </txp:block>
        </div><!-- #secondary -->
    </div><!-- #content -->

<txp:output_form form="footer">

Expandor template: articles

<txp:extends template="skeleton"> <!-- this indicates: expand **skeleton** template -->

<txp:block name="primary">  <!-- the content of this block fills in the block "primary" on skeleton template -->
         <txp:article status="live" limit="10" />
</txp:block>

<txp:block name="secondary" super="append">  <!-- the content of this block PREPENDS TO the block "secondary" on skeleton template -->
         <txp:related_articles />
     </div>
</txp:block>

So, the “secondary” block will get filled with the content on the skeleton template plus the content of the block, that will be prepended or appendend.

———-
Regarding the SEO advice of putting the nav at bottom.
I won’t agree about navigation on top affecting SEO that much. In fact, if your content is first, but your site hasn’t good internal linking from inside the content, it may affect it negatively. And crawlers may not get to the bottom navigation bar, so not following your internal links.
Sites I’ve done with nav on top have good SEO.

And, in fact, suppose it is good for SEO… but the studies indicates it isn’t good for usability/accesibility: Source Order, Skip links and Structural labels
Accesibility is always highest priority.

Last edited by maniqui (2008-12-24 19:09:31)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#4 2008-05-03 08:28:53

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: <txp:extends />, <txp:block></txp:block>, expanding templates

And, in fact, suppose it is good for SEO… but the studies indicates it isn’t good for usability/accesibility: Source Order, Skip links and Structural labels
Accesibility is always highest priority.

First: that was an example, I didn’t say that it must be commented. I just commented on it later, to explain why i put the navigation at bottom. It also was straight copy from one of my projects, where that makes bonus donut. But now as I mentioned it, it got the negative effect that I was trying to remove :D Well here goes as it came up:

That is true, but it depends about the site itself, and the target area. In example SEO company, they could but the navigation below the main content paragraph, but before sidebars – as that is SEO. Also sites that are “useless” with out styles, kindly can put the efforts to the SEO. In example webdesign company that sells designs. Also site that is MFA can put the navigation somewhere silly place. That is for money, not for navigation ;)

Also, it depends how you build your navigation and how many links it includes. Also is your real SEO navigation there or not, or are those links just dummies that have no efect to the seo. Or is there also bottom navigation, and could i put them all together and then move them with CSS.

Also the amount of content and internal links make difference. If there is a lot of content per page, then the navigation could be better at the top. Also blogs without target area or main subject can put (even long) navigation at top with out any loss, the navigation can have good effect in those cases.

As I said at first: It doesn’t mean put your navigation bottom or top. There isn’t rules. Cases are unique, so is the accesibility. What becomes to all personal hobby sites: don’t even bother. Those cases you just should be happy about the site, and not to worry too much ;) But if the optimizing is the hobby, then it’s opposite.

I don’t understand why people fight over these things… :) Nerds with brain freeze (including me) :P

Last edited by Gocom (2008-05-03 08:39:02)

Offline

#5 2008-05-03 11:53:16

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

Re: <txp:extends />, <txp:block></txp:block>, expanding templates

If <txp:extend /> were a container tag, one could implement this as a plugin.
It wouldn’t even be a very complex or big plugin… I’m guessing it can be done in just 1 kB of code.

I would recommend changing the ‘super’ attribute name. Turn that into something that instantly makes sense (others can probably come up with something better): do="prepend|append" or add="pre|post" (short and simple), both performing a replace action if not set.

And since TXP uses ‘page’ and ‘form’ instead of ‘template’ (who ever thought those names was a good idea?), it may be best to have both ‘page’ and ‘form’ attribute names for the extend tag, so you can not only extend ‘page’ but ‘form’ as well.

Hmm… now that I think about it, even with extend as a self-closing tag, this could easily be done, but the extend tag would have to be placed at the very bottom of the page. This is slightly faster (because it reduces the nesting level by 1 step, but not as flexible as using it as a container tag (which would allow for other code above and below the extend tag) and unlike the container tag it probably wouldn’t allow nested extend tags.

Last edited by ruud (2008-05-03 12:07:55)

Offline

#6 2008-05-03 15:31:45

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: <txp:extends />, <txp:block></txp:block>, expanding templates

ruud wrote:

I would recommend changing the ‘super’ attribute name. Turn that into something that instantly makes sense (others can probably come up with something better): do="prepend|append" or add="pre|post" (short and simple), both performing a replace action if not set.

Yes, that would be better. I was still using Django terminology ({% block.super %})

but not as flexible as using it as a container tag (which would allow for other code above and below the extend tag) and unlike the container tag it probably wouldn’t allow nested extend tags.

I’m not sure if it makes sense to have more code outside the extend tag (or what is the same, to have code outside a expandor block). In Django, you have the extend (self-closing) tag at the top of the template (page) and then you re-define blocks.
So, any code outside a block, where is it going to “land” in the expanded page?
This may make harder to “follow” how blocks are filled and how pages are expanded.

Finally, I’m still not convinced if this way of working fits in TxP logic/semantics/way-of-thinking.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#7 2008-05-03 16:08:57

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

Re: <txp:extends />, <txp:block></txp:block>, expanding templates

I meant this when I was talking about having code outside extend tags:

some HTML+TXP tags above
<txp:extend>
  <txp:block> only block tags inside extend </txp:block>
</txp:extend>
some HTML+TXP tags below

This may not make as much sense when talking about TXP pages, but might be useful when using it combined with TXP forms (where the extend tag is used to extend a form instead of a page).

Last edited by ruud (2008-05-03 16:09:38)

Offline

Board footer

Powered by FluxBB