Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-01-06 23:45:46

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

if_article_id on article-list context

Hi,

on article list context, I would have expected that txp:if_article_id woudl return false and so, output the code after txp:else.

<txp:article_custom category="amenities" sort="FIELD(ID,23,24,25,26)" wraptag="ul">
    <li>
    <txp:if_article_id>
       <span><txp:title /></span>
    <txp:else />
       <txp:permlink><txp:title /></txp:permlink>
    </txp:if_article_id>
    </li>
</txp:article_custom>

On the tag trace for the article-list context, there is:

<txp:if_article_id>
</txp:if_article_id>
<txp:if_article_id>
</txp:if_article_id>
<txp:if_article_id>
</txp:if_article_id>
...

On the tag trace for the individual-article context:

<txp:if_article_id>
    [<txp:if_article_id>: true]
    <txp:title />
</txp:if_article_id>
<txp:if_article_id>
    [<txp:if_article_id>: false]
</txp:if_article_id>
<txp:if_article_id>
    [<txp:if_article_id>: false]
</txp:if_article_id>
...

Last edited by maniqui (2009-01-06 23:46:31)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#2 2009-01-07 00:20:52

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

Re: if_article_id on article-list context

maniqui wrote:

on article list context, I would have expected that txp:if_article_id woudl return false and so, output the code after txp:else.

You realize that if_article_id returns the contained content, if id -attributes value matches the ID of the article (beeing output at that time, in list and/or individual context)?

If you need different outputs, use if_individual_article and/versus if_article_list. If you require to output only a specific articles, you can use article_custom’s id attribute. Also adding whole uncut tag trace is smart.

Offline

#3 2009-01-07 17:19:37

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

Re: if_article_id on article-list context

Hi Gocom, thanks for your reply.

I forgot to say that, when on article-list context, the <txp:if_article_id> A <txp:else /> B </txp:if_article_id> doesn’t return A nor B.
It’s like it’s not true nor false.
On article list context, I expect it to be always false: it’s not the ID of the article being output at that time, but the ID of the article being rendered on individual (permlink) context. If it were the ID of the article being output at that time, it will be always true, right?.

So, back to what I’m trying to achieve: a simple menu where the currently displayed article (on individual-article context, aka permlink) is not linked. But if the menu is rendered on an article-list context, every item on the menu should be linked.

Yes, you are right: a combination of if_individual_article and if_article_list should do the work.
Something like this:

<txp:article_custom category="amenities" sort="FIELD(ID,23,24,25,26)" wraptag="ul">
    <li>
    <txp:if_article_list>
       <txp:permlink><txp:title /></txp:permlink>
    <txp:else />
      <txp:if_article_id>
         <span><txp:title /></span>
      <txp:else />
         <txp:permlink><txp:title /></txp:permlink>
      </txp:if_article_id>
    </txp:if_article_list>
    </li>
</txp:article_custom>

That will work, for sure.
But then, I think that if_article_id alone could return false on article-list context, so it could work similar to if_article_list.

What do you think?

(I will try to post the full tag trace later).


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#4 2009-01-07 18:16:35

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

Re: if_article_id on article-list context

Hi Julián, I had exactly the same problem last week, it took quite some time to figure out what would work… I don’t remember exactly all the combinations I tried, but in the end wrapping the if_individual_article tag around the entire article_custom tag was the answer. I racked my brains about the reason, but it must be something like that inside article_custom, which is always an article list, if_individual_article will therefore allways return false, so that’s why it has to be outside the tag. Or something like that…

This is the code that finally worked:

<txp:if_individual_article>
	<txp:article_custom sidebar2="ja" sort="custom_6 asc" limit="5">
		<txp:if_article_id>
		<txp:else />
			<h4><txp:title /></h4>
			<txp:excerpt />
		</txp:if_article_id>
	</txp:article_custom>
<txp:else />
	<txp:article_custom sidebar2="ja" sort="custom_6 asc" limit="5">
		<h4><txp:title /></h4>
		<txp:excerpt />
	</txp:article_custom>
</txp:if_individual_article>

Offline

#5 2009-01-07 18:29:32

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

Re: if_article_id on article-list context

Hi Els,

I don’t want to contradict the Queen of Tags, but if_individual_article and if_article_list should work inside an article_custom tag.
In other words, as we know, article_custom is context insensitive.
if_individual_article (and if_article_id) should return true or false inside an article_custom (or any other container tag, or even any form), depending on the context where they are being evaluated.

But then you said you tested them inside article_custom and they didn’t work… weird. I will make my own tests any time soon.

Thanks.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#6 2009-01-07 19:43:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,816
Website GitHub

Re: if_article_id on article-list context

Just to throw an oar in, <txp:if_article_id> — without any id attribute — will actually return nothing in an article list context because there is no ‘article’ outside the article list to compare the value to.

If you had 4 articles with IDs 4, 3, 2, 1 (from most recent down to least recent, i.e. the default Posted desc), consider this:

<txp:article_custom limit="4" section="articles">
  <txp:if_article_id>
    YES
  <txp:else/>
    NO
  </txp:if_article_id>
</txp:article_custom>

Then:

  • if you were viewing article #3 you would see NO YES NO NO (ID: 4 3 2 1)
  • if you were viewing article #4 you would see YES NO NO NO (ID: 4 3 2 1)
  • if you were not viewing any article (i.e. in a pure section) you would see nothing. As maniqui said it is actually not true or false because there’s nothing to test it against

But with this:

<txp:article_custom limit="4" section="articles">
  <txp:if_article_id id="3">
    YES
  <txp:else/>
    NO
  </txp:if_article_id>
</txp:article_custom>
  • if you were viewing article #3 you would see NO YES NO NO (ID: 4 3 2 1)
  • if you were viewing article #4 you would see NO YES NO NO (ID: 4 3 2 1)
  • if you were not viewing any article (i.e. in a pure section) you would see NO YES NO NO (ID: 4 3 2 1)
  • … and so on

Because the article_custom is always outputting articles 1, 2, 3, and 4 on every page view, since they’re the most recent articles you’ve written. It’s now not comparing what’s ‘outside’ the list but what’s ‘inside’ the list as it iterates over the articles.

It becomes more obvious if you have more articles because article_custom returns the most recent 4 (in the example above) so if you added 4 more articles with IDs 8, 7, 6, 5 the above code outputs: NO NO NO NO (ID: 8 7 6 5) all the time because none of the 4 most recent articles that the tag returns, matches ID 3.

It’s totally mad and does your head in, but that’s why Els’ code works because it only calls the context-sensitive <txp:if_article_id /> (no attributes) inside a <txp:if_individual_article>.

Just remember:

  1. if_article_id without attributes compares the current article (as it processes the list tag) with the currently viewed article (i.e. the one outside the tag). If there ain’t one outside the tag, you’ll get nothing, zip, nada, nil, nul.
  2. if_article_id with an ID attribute compares the current article (as it processes the list tag) with the value of the ID you gave the tag. If it matches none of the articles, you get false for every article in the list and — of course — true at the point it matches one

EDIT: if someone can put that into plain, concise English, perhaps this sort of thing ought to go in textbook ?!

EDIT2: And don’t ask me why it does this either: I just read the code! :-)

EDIT3: Sorry I keep editing the code above; I was testing it on an install with loads of articles and wrote it as if the articles were in ascending order by mistake!

Last edited by Bloke (2009-01-07 20:21:09)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2009-01-07 20:47:50

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

Re: if_article_id on article-list context

maniqui wrote:

I don’t want to contradict the Queen of Tags,

Since you’re the King of Tags, we should be allowed to contradict each other ;)

I find it really hard to put into words how I think it works (or rather: how I feel it works, because you can’t really call all that tumbling around in my brains ‘thinking’…). This new context sensitivity offers a lot of new possibilities, but so far I find it hard to fit the logic of the workings into a concrete model that I can work with. I figure it out and then have to figure it out again every next time I need it :)

I’m now trying to make sense of Stef’s post…

Offline

#8 2009-01-07 21:02:37

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,816
Website GitHub

Re: if_article_id on article-list context

Els wrote:

I’m now trying to make sense of Stef’s post…

Standard disclaimer applies if your brain ejects :-)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#9 2009-01-07 21:38:25

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,934
Website GitHub

Re: if_article_id on article-list context

Just to throw an oar in, <txp:if_article_id> — without any id attribute — will actually return nothing in an article list context because there is no ‘article’ outside the article list to compare the value to.

I understand Els code as displaying the list of articles skipping the currently shown article when showing a single article and simply showing the whole list when on an article list page.

Stef, if <txp:if_article_id> returns nothing in the article context, does that mean Els’ code can be simplified to have only the first part since the ‘else’ condition will always apply for article lists:

	<txp:article_custom sidebar2="ja" sort="custom_6 asc" limit="5">
		<txp:if_article_id>
		<txp:else />
			<h4><txp:title /></h4>
			<txp:excerpt />
		</txp:if_article_id>
	</txp:article_custom>

right? wrong?

Last edited by jakob (2009-01-07 21:40:23)


TXP Builders – finely-crafted code, design and txp

Offline

#10 2009-01-07 21:55:29

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,816
Website GitHub

Re: if_article_id on article-list context

jakob wrote:

if <txp:if_article_id> returns nothing in the article context, does that mean Els’ code can be simplified to have only the first part since the ‘else’ condition will always apply for article lists:

Sadly no. When it returns nothing, it actually returns nothing : not false, not true, it just kinda dies and returns empty-handed. Thus, since EvalElse() is never called, the entire tag and container, including <txp:else /> is ignored; as if it wasn’t there.

Quite why it returns nothing instead of false only the devs can answer. Must be a reason and it may be so that the two ‘types’ of check are possible: one in context and one not in context, comparing an actual ID. But if so, it’s an odd way to do things. I honestly don’t know the reason, but it seems weird.

Last edited by Bloke (2009-01-07 21:58:09)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#11 2009-01-07 22:59:15

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

Re: if_article_id on article-list context

If you’re in article list context, you should specify the id attribute for the <txp:if_article_id> tag, otherwise it is meaningless (since every article has an ID).

On individual article pages (permlink) the ID is set by default to the ID of that article which makes it evaluate to TRUE. I’m not quite sure how that’s useful though.

Offline

#12 2009-01-07 23:12:12

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,816
Website GitHub

Re: if_article_id on article-list context

ruud wrote:

If you’re in article list context, you should specify the id attribute for the <txp:if_article_id> tag, otherwise it is meaningless (since every article has an ID).

Makes sense. I’ll put that as the recommended behaviour in textbook.

On individual article pages (permlink) the ID is set by default to the ID of that article which makes it evaluate to TRUE. I’m not quite sure how that’s useful though.

I’d see it being useful(ish) if you had a sidebar of articles generated via <txp:article_custom />. You could highlight the article being viewed with:

<txp:if_individual_article>
	<txp:article_custom limit="10">
		<div <txp:if_article_id>class="current"</txp:if_article_id>>
			<h4><txp:title /></h4>
			<txp:excerpt />
		</div>
	</txp:article_custom>
</txp:if_individual_article>

No? Perhaps it’s a tad esoteric? (and untested, so it might not work)

Last edited by Bloke (2009-01-07 23:16:33)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB