Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-01-18 16:57:28

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

One Page (template) to rule them all

(sorry, tired LoR expression)

[EDIT: This <strike>has been solved</strike> <strike>is still being fiddled with, for the most part</strike> has been put on the back burner. <strike>Jump down to reply #7 for the solution</strike>. By all means, continue with the discussion.]

It seems the rage these days is to build TxP sites in two dimensions: advantageously and economically. Advantageously suggests using as few plugins as absolutely necessary so your sites require less overhead management and are forward compatible with new releases of TxP. Economically means to suggest using as few building blocks as necessary, particularly Pages and Forms, so your architecture is light and tight.

The key to it all is to use TxP’s powerful Tags in clever ways to produce both functional and economical site architecture. Efforts are slowly being made to bring the various uses of Tags to light (e.g., here, here, and here) but we can all pitch in with that effort.

As an example of what I’m getting at, here’s a little assignment to ponder. Let’s say we’re faced with the following ingredients:

  • a two column layout (main reading area, sidebar for article lists)
  • 4 Sections plus the home (5 Web views)
  • 1 Page (default = “to rule them all”)
  • a hanful of Categories (associates articles to the various Sections’ sidebars)

EDIT: following paragraph revised…

In each Section view, the main reading area will simply be the latest published article pulled from the associated Category for articles in that Section (i.e., only 1 article displayed at a time). The rest of the articles in that given Category (including the latest article) will be listed in the sidebar as linked article titles (a typical article list), and should any of them be clicked, that given article will swap out the latest article being viewed in the main content area, while the list will remain intact in the side column. That is the behavior for each given Section. The behavior is the same in the other sections, except it will be a different set of articles being displayed (the articles associated to the given Section).

In this scenario, everything in the Page template is going to be the same from on Section to another, except for the categorical lists that will change in the respective sidebar. <strike>Hence, it’s safe to assume we will be going with conditional Tags here to get things done</strike>. The real question is how far can we go before we have to resort to using another Page template (remember, nothing is changing except the categorical lists)?

Here is a successful first step, though I’m not sure it’s the right step to build on later:

In the main reading area (“mra”) we might use this as simple output for the single, full article…

<div id="mca">
<txp:article form="default" limit="1" />
</div>

and in the sidebar (“sidebar”) we might go with this…

<div id="sidebar">
<txp:if_section name="section1,section2,section3,section4">
<txp:output_form form="mListHeader" />
<txp:article_custom listform="alstDefault" limit="5" />
<txp:else />
<txp:output_form form="mSearch" />
<txp:output_form form="mListHeader" />
<txp:article_custom listform="alstDefault" limit="5" />
</txp:if_section>
</div>

The mra is easy, and behaves properly: when you move from Section to Section via navigation, you’ll see the latest article posted to that Section in the main view.

The “sidebar” is a bit more abstract. In one respect we have two sidebar displays, one for the home page and one for the rest of the Sections. The conditional says, if we are in “section1,section2,section3,etc.” output this set of custom Forms in the sidebar, for everything else (which is only going to be the home page), output this other set of custom Forms. In this case (for simplicity), the only difference between the two sets of Forms is Search control being added to the home page.

Up to this point, everything works fine except for one thing: the article lists in the various Section sidebars produce exactly the same list of articles, namely everything that’s assigned to all 4 Sections. That is expected, actually, considering we have not used Category rules in the code yet.

The objective is to make it so that as one goes from Section to Section they see only articles in the sidebar lists that are respectively assigned to Categories, which are themselves created for use in respective Sections. The association of Categories to Sections is 1-to-1 (like articles are to Sections), though you may have two unique Categories per a given Section, for example:

  • section1 : cat-A
  • section2 : cat-B
  • section3 : cat-C, cat-D
  • section4 : cat-E, cat-F

The question, finally, and thus the assignment is… how do you further modify the sidebar code to parse categorized articles to their respective Sections so you don’t get the cumulative article list in each Section?

I’m guessing the solution, if there is one, lies in using more conditionals somehow, maybe even conditionals within conditionals. Ideas?

Attention: I know this is easily solved with the creation of more Pages, but that’s not what I’m after. Nor, as you should see by now, do I want a plugin suggestion. The objective is one Page to rule them all using Tags, Frodo, magical Tags.

Last edited by Destry (2006-01-28 17:31:47)

Offline

#2 2006-01-18 18:11:29

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: One Page (template) to rule them all

Here I am thinking that you must be asking a really difficult question, but I honestly think that using <txp:article /> instead of <txp:article_custom /> in the sidebar would do exactly what you want. At least in this case, where all articles in a certain category are in the same section.

Of course if you want them sorted by category as well as by date posted (this is possible), as well as have lists per category with the category title as a header, it would require something more elaborate.

Offline

#3 2006-01-18 18:22:30

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: One Page (template) to rule them all

Destry wrote:
Economically means using as few building blocks as necessary, particularly Pages and Forms, so your architecture is light, tight, and right.

And :

Hence, we are obviously going to be using conditional Tags here to get things done. The real question is how far can we go before we have to resort to using another Page template (remember, nothing is changing except the categorical lists)?

Maybe your post wasn’t about efficiency (human, and both client & server machines) but if it was I’m not sure these quotes are the same.

A 2 pages vs 1 with multiple txp:if. I guess, for the machines, it depends on how easy it is for TXP to switch from a Textpattern tag to a PHP’s case (or similar).

Offline

#4 2006-01-18 19:05:12

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: One Page (template) to rule them all

You can always rely on Jeremie to get technical ;) But yeah, I see what you’re saying, using “conditionals” and “efficiency” can be controversial. So then, that’s part of the equation too…keeping the conditionals light. Did you have a solution, just the critique, or are you indirectly suggesting this is just not possible without more Pages?

@doggiez: Unfortunately, just using <code><txp:article ></code> doesn’t work. I see what your line of reasoning is, but there’s apparently something missing with respect to parsing the articles to the right Section.

Offline

#5 2006-01-18 19:43:11

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: One Page (template) to rule them all

@doggiez: Unfortunately, just using <code><txp:article ></code> doesn’t work. I see what your line of reasoning is, but there’s apparently something missing with respect to parsing the articles to the right Section.

It doesn’t??? I really thought that when you’re on a section page, <txp:article /> would show only articles in that section… and since you can only be in one section at the time I assumed this would work. If I understood your explanation correctly, we’re not even on an individual article page, but on the section homepage. So I wonder why it doesn’t work.
Well, one is never too old to learn ;) (And of course I didn’t try this before posting…)

Offline

#6 2006-01-18 20:15:53

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: One Page (template) to rule them all

<code>
<txp:if_section name=“section1,section2”>
<txp:if_article_list>
<txp:article listform=“title” />
</txp:if_article_list>
</txp:if_section>
</code>
in my sidebar is working for me! Articles in section1 can have one of five categories assigned (only category1). Articles in section2 can have one of three categories as category1, and one of twelve or none as category2. Without the <txp:if_article_list> on an individual article page it just displays the same article, so you would need some more conditionals to display the same article list as on the section home page. The only thing I can’t work out at the moment is sorting by multiple fields.

Offline

#7 2006-01-18 20:51:36

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: One Page (template) to rule them all

That was it! The <code><txp:if_article_list> …list piece… </txp:if_article_list></code> made the difference. Thanks for the snippet to make it clear. So, apparently <code><txp:article /></code> by itself won’t do it; has to be done with the article list conditional. That’s not something I think people would find very intuitive (obviously), and thus good we have it ironed out. (I guess we can move this one to “Tag Examples”, and I’ll try and work on a better write-up.)

To be clear, the entire code block for the sidebar now is…

EDIT: code edited to reflect discussion later in this thread.

<div id="sidebar">
<txp:if_section name="section1,section2,section3,section4">
<txp:output_form form="mListHeader" />
<txp:if_article_list>
<txp:article listform="alstDefault" limit="5" />
</txp:if_article_list>
<txp:else />
<txp:output_form form="mSearch" />
<txp:output_form form="mListHeader" />
<txp:if_article_list>
<txp:article listform="alstDefault" limit="5" />
</txp:if_article_list>
</txp:if_section>
</div>

which shouldn’t be to much of a burdon as Jeremie was concerned.

…as well as have lists per category with the category title as a header, it would require something more elaborate.

I think this is the next step. Where two Categories associated to one Section are displayed in the sidebar as two lists.

Anyway, thanks for the time, doggiez. Very insightful.

Last edited by Destry (2006-01-28 09:45:18)

Offline

#8 2006-01-18 22:02:32

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: One Page (template) to rule them all

I was not criticizing. Just that if your goal was speed, it may not be the most efficient path. But templates and code example is always good anyhow.

Offline

#9 2006-01-18 22:33:35

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: One Page (template) to rule them all

Forgive my ignorance but doesn’t using a second “article” tag in the sidebar create a potential problem with doubling coments and comment_form unless you have “auto append” switched off?

I was thinking that using something like <code><txp:article_custom section=”<txp:section /> />”</code> might do the trick but I haven’t tried it out myself.

You could also reduce your code by not including attributes where you are using the default value. For example “form” uses the default form by default, “sortby” uses Posted by default etc.


Stuart

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#10 2006-01-18 22:50:43

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: One Page (template) to rule them all

Forgive my ignorance but doesn’t using a second “article” tag in the sidebar create a potential problem with doubling coments and comment_form unless you have “auto append” switched off?

Excuse me, I don’t think that’s your ignorance, it’s probably mine ;) I have it switched off, and hardly use comments, so I hardly ever think about comments. I suppose you’re right.

I was thinking that using something like <code><txp:article_custom section=”<txp:section /> />”</code> might do the trick but I haven’t tried it out myself.

Unfortunately you can’t put txp tags inside other txp tags :(

Offline

#11 2006-01-18 23:05:02

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,909
Website

Re: One Page (template) to rule them all

OK, so this may not be the way to go after all, and thus the assignment is still open for ideas.

Forgive my ignorance but doesn’t using a second “article” tag in the sidebar create a potential problem with doubling coments and comment_form unless you have “auto append” switched off?

I don’t know, good question. So you’re suggesting that even though they’re used in the sidebar as list output, and have no comment invites associated to them (only article titles), they’re still going to impact the commenting functions potentially used in the main reading area (the single article)? Possible to elaborate a bit?

Wait, it’s going to be one or the other, right (if this, then that, if not, then other one), would that not nullify the “doubling” effect you suggest? I’m just throwing things out there.

Yeah, according to this FAQ, no tags within attributes. Though I see reference in the forum of people using Tags within XHTML tags…be nice to get the clear dope on this. Do nested Tags work in some instances but technically shouldn’t?

@Jeremie: I didn’t think you were, but I was having a little trouble following you. I think we’re clear now though. You were talking about technical efficiency, and I was more referring to efficiency in terms of overhead management (the human quality). Both valid points.

Last edited by Destry (2006-01-18 23:13:43)

Offline

#12 2006-01-18 23:18:40

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: One Page (template) to rule them all

Destry wrote:

Yeah, according to this FAQ, no tags within attributes.

That FAQ by the way does give a possible use of the article_custom tag for your template, instead of Stuart’s suggestion.

Though I see reference in the forum of people using Tags within XHTML tags…be nice to get the clear dope on this.

Sure. Things like <a href="<txp:site_url />section1/">Section 1</a> work.

Do nested Tags work in some instances but technically shouldn’t?

You can nest conditional tags like this
<code>
<txp:if_section name=“section1”>
<txp:if_category name=“category1”>
blah
</txp:if_category>
</txp:if_section>
</code>
but you can’t nest for example two if_section tags.

Offline

Board footer

Powered by FluxBB