Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-10-03 09:30:48

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

Tag architecture challenge for complex conditional output

Is this possible? Please tell me it’s possible, because I fear it’s not without custom scripting and even then I wouldn’t know.

Also, might it be a better idea if the data table in the second display was really its own table in the database instead of being awkwardly created with a bunch of Txp articles? Realizing, of course, there would need to be some nifty new plugin that would interface custom table creation in the admin-side. Hint-hint.

Offline

#2 2013-10-03 20:18:52

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

Re: Tag architecture challenge for complex conditional output

Topics are categories? Then gbp_permanent_links is the way.

Why wouldn’t it be possible? I don’t see anything far-fetched in your model, unless I’m missing something. I assume a table row contains only fields from the same article?

Offline

#3 2013-10-07 11:11:09

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

Re: Tag architecture challenge for complex conditional output

Yes, topics=categories.

Well I’m glad you think it’s possible, Els. The problem is I don’t know how to do it. ;)

After all these years I still can’t figure out conditional tags. It seems no matter what I try, it’s always wrong. I’m just guessing in the dark every time.

This is a more immediate problem, and I can’t even figure this out…

Section=“Foo”, Page=“Foo”

<txp:if_?> {article output code here for /foo/article-title clicks}
<txp: else /> {sticky article <body> code here for /foo landing clicks}
</txp:if_?>

Are you supposed to use if_article_list? if_individual_article? if_section? It’s never clear to me. I waste hours trying to troubleshoot stuff like this.

A “rangent” to nobody in particular…

There should be some kind of conditional tag structure builder for taking the abstract out of building these common tag structures. Not like the article and image tag builders that focus on a single tag and it’s attributes, but rather for conditional nesting. For example, my problem above could be a structure option called If article, else sticky. Then you open a structure builder form and choose that option and bam, the basic tags structure is output like above, replacing “?” with proper tag conditional.

Maybe some attributes are added if they are certain to have specific values, but otherwise attributes can be left for the person to fiddle with, at that point at least the tag structure is correct.

Offline

#4 2013-10-07 11:19:13

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

Re: Tag architecture challenge for complex conditional output

Or lets say you wanted to have a list of articles under the sticky post in the previous example. That could be a second structure option called If article, else sticky and list, and, I guess give you something like this…

<txp:if_?> 
     {article output code here for /foo/article-title clicks}
<txp: else /> 
     {sticky article <body> code here for /foo landing clicks}
     {article list code here for some article list}
</txp:if_?>

And you could imagine maybe some examples where there are nested conditionals for different scenarios (e.g., if_article_image, if_category, etc). It seems these structural scenarios could be modeled and generated based a simple name process. I.e., open form, click the name of structure model, and the structure code is output for copy/paste, where the author could then expand on the attributes, etc. It’s a lot easier to deal with attributes when you have the base tag structure correct first, and this would give people confidence that they did have the base structure correct, and thus could focus troubleshooting at a finer-grain if necessary (attributes… whatever).

Offline

#5 2013-10-07 14:00:08

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

Re: Tag architecture challenge for complex conditional output

Hi Destry.

Re: if_individual_article and if_article_list: one is the “negative” of the other one.

<txp:if_article_list>
  ...we are in an article list context, a.k.a. a "section landing page" (ie. /foo)
  {sticky article <body> code here for /foo landing clicks} 
  {article list code here for some article list}
<txp:else />
  ... else... we are necessarily in an individual article context.
  {article output code here for /foo/article-title clicks}
</txp:if_article_list>

The above is exactly the equivalent of:

<txp:if_individual_article>
  we necessarily in an individual-article context.
  {article output code here for /foo/article-title clicks}
<txp:else />
  ... else...  ...we are necessarily in an article-list context, a.k.a. a "section landing page" (ie. /foo)
  {sticky article <body> code here for /foo landing clicks} 
  {article list code here for some article list}
</txp:if_individual_article>

Re: if_section. This one only test if the current section is “foo”, not caring at all about if it’s an article-list context or an individual-article context. So, no, it can’t test if we are in a section landing page (/foo).

One interesting thing of gbp_permanent_links, a rather obscure feature, is that you can “set free” your templates from some logic. That is, you can configure rules so a certain URL format uses a certain template, and another certain URL format uses another URL template. An “URL dispatcher” kind-of.

In other words, you can set a rule in a way that:

  • An URL matching /section/article-url-title/ will use a certain page template, for example: my-individual-articles template.
  • An URL matching /section/ will use another certain page template, for example: my-section-landing-page template.

A setup like that can make if_article_section and if_individual_article a thing of the past. :)

Edit: some error.

Last edited by maniqui (2013-10-08 13:11:23)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#6 2013-10-07 21:51:43

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

Re: Tag architecture challenge for complex conditional output

In addition to what Julián wrote, could this get you started?

<txp:if_section name="x">
	// we are in section 'x', could be the section landing page, an individual article page, a category page, author page, ...
	<txp:if_article_list>
		// can be any of the above, except an individual article page
		<txp:if_category>
			// this is a category page in section 'x' (/x/category-name or /?s=x&c=category-name
		<txp:else />
			<txp:if_author>
			// this is an author list page in section 'x' (/x/author-name or /?s=x&author=author-name
			<txp:else />
				<txp:if_search>
				// let's exclude the search page too (/x/?q=whatever)
				<txp:else />
					// this must be the section landing page (/x/)
				</txp:if_search>
			</txp:if_author>
		</txp:if_category>
	<txp:else />
		// this is an individual article page in section 'x' (/x/article-title), use if_article_image, if_article_category etcetera here
	</txp:if_article_list>
</txp:if_section>

Offline

#7 2013-10-08 06:24:46

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

Re: Tag architecture challenge for complex conditional output

I haven’t yet put these to test, but I will go over these lessons again and again.

You’ve done an amazingly simple job of explaining the abstract, Julian.

And you’re clearly a white wizard now, Els.

Offline

#8 2013-10-08 07:08:43

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

Re: Tag architecture challenge for complex conditional output

Julian, for the moment this is what I’m trying to get working (keeping it simple at first)…

<txp:if_individual_article>
  {article output code here for /foo/article-title clicks}
<txp:else />
  {sticky article <body> code here for /foo landing clicks} 
</txp:if_individual_article>

And this is my code (again, keeping it simple here)…

<txp:if_individual_article>
     <txp:article_custom section="articles" limit="1">
           {all the article pieces needed; smd_bio stuff, etc. }
     </txp:article_custom>
<txp:else />
     <txp:article_custom status="sticky">
            <txp:body />
     </txp:article_custom>
</txp:if_individual_article>

But I’m getting the same article-title output at both /foo and /foo/article-title locations. I.e., at section landing, I’m not getting the sticky <body> content. If I change the tag from article_custom to article, it makes no difference.

Offline

#9 2013-10-08 07:23:35

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

Re: Tag architecture challenge for complex conditional output

<txp:article_custom /> won’t return an individual article, the tag is only for article lists (can also be a list of only one article), so you need to change at least the first one to <txp:article />. The second one can be an article tag too, but the article_custom tag as you have it now should return the sticky article. You did check if a sticky article exists?
Have a look at the tag trace (see link in my signature), if it doesn’t tell you anything please post it here?

Offline

#10 2013-10-08 09:32:28

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

Re: Tag architecture challenge for complex conditional output

So my code now looks like this, and nothing has changed. I still get the latest full article appearing in both locations…

<txp:if_individual_article>
     <txp:article limit="1">
           {all the article pieces needed; smd_bio stuff, etc. }
     </txp:article>
<txp:else />
     <txp:article_custom status="sticky">
            <txp:body />
     </txp:article_custom>
</txp:if_individual_article>

Yes, there is a sticky article. The site is in “debugging” mode and there are no errors or tag traces being shown on the page after refresh. [Ed. looking at tag trace now, it’s long.]

In the case of the first article, if I remove the limit="1", all articles in the /foo section are output to the /foo landing section.

I should clarify, in case it makes a difference. The page template contains an output_form tag calling the form that contains the code above.

Last edited by Destry (2013-10-08 09:35:55)

Offline

#11 2013-10-08 10:00:55

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

Re: Tag architecture challenge for complex conditional output

Unfortunately, I’m not able to decipher the hieroglyphs that are the tag trace. I’ll have to stew on it.

Offline

#12 2013-10-08 10:58:29

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

Re: Tag architecture challenge for complex conditional output

Hmm… I think I see what might be the problem. I have another form that loads the top part of the template. Some of the code for that is this…

   <txp:if_individual_article>
      <title><txp:article><txp:title /></txp:article> – <txp:section /> | <txp:site_name /></title>
   <txp:else />
      <title><txp:section /> | <txp:site_name /></title>
   </txp:if_individual_article>

I’m not even sure where I got that from, I think from the default template or something on a clean install.

Anyway, it’s probably not in context. It’s also giving some strange Title output that doesn’t make sense. I’ll monkey with that.

Offline

Board footer

Powered by FluxBB