Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-10-17 10:25:40

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

article_custom and category matching head scratcher

I’m calling an article form via article_custom and I’m not quite achieving what I want to do. Here’s what I’m trying to achieve:

Check for articles with a given pair of tags. If at least one article exists, create the following table markup once: open table, open thead, open th, close th, close thead and open tbody with a view to having article(s) matching the criteria in tr blocks later in the form. After the article(s) has/have been output, finish the table by closing tbody and closing table.

The problem I have is that I can check for the category pair, and the first article output does not have an expiry, but the table markup is not being created.

Article form

<txp:if_article_category name="fruit" number="1"><!-- if the first category is fruit -->
	<txp:if_article_category name="citrus" number="2"><!-- if the 2nd category is citrus -->
		<txp:if_expires><!-- if the article has an expiry date -->
		<txp:else /><!-- else -->
			<txp:if_first_article><!-- if this is the first article in the list -->
				<table>
				<thead>
					<th>Table head text</th>
				</thead>
				<tbody>
			</txp:if_first_article>
		</txp:if_expires>
	</txp:if_article_category>
</txp:if_article_category>

I’ve sanitised some of the code above to remove my own references and I’m combing through a tag trace at the moment. Any pointers or tips are gratefully received.

Offline

#2 2012-10-17 10:52:29

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

Re: article_custom and category matching head scratcher

OK, interesting findings. I scaled things right back and tried this:

<txp:if_article_category name="fruit" number="1">
	<txp:if_article_category name="citrus" number="2">
		<txp:if_expires>
		<p>expires<p>
		<txp:else />
		<p>does not expire<p>
		</txp:if_expires>
	</txp:if_article_category>
</txp:if_article_category>

There are three articles found (as expected), and the following is output:

does not expire
expires
expires

So, it’s safe to assume the first article does not expire, the second does and the third also expires. Right?

I changed my form a little:

<txp:if_article_category name="fruit" number="1">
	<txp:if_article_category name="citrus" number="2">
		<txp:if_expires>
		<p>expires<p>
		<txp:else />
			<txp:if_first_article>
			<p>is first</p>
			</txp:if_first_article>
			<p>does not expire</p>
		</txp:if_expires>
	</txp:if_article_category>
</txp:if_article_category>

I would expect the following output:

is first
does not expire
expires
expires

I don’t get that, I get this:

does not expire
expires
expires

So, no is first at the top. Does the if_first_article tag work in this context, or have I done something wrong?

Last edited by gaekwad (2012-10-17 10:52:57)

Offline

#3 2012-10-17 11:31:37

etc
Developer
Registered: 2010-11-11
Posts: 5,397
Website GitHub

Re: article_custom and category matching head scratcher

I guess if_first_article looks in the scope of article(_custom), not in if_article_category?

Offline

#4 2012-10-17 11:32:28

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

Re: article_custom and category matching head scratcher

Right, I stripped it down even further and took the expiry conditions out. This is weird.

<txp:if_article_category name="fruit" number="1">
	<txp:if_article_category name="citrus" number="2">
		<p><txp:if_first_article>is first - </txp:if_first_article><txp:if_last_article>is last - </txp:if_last_article><txp:title /><p>
	</txp:if_article_category>
</txp:if_article_category>

I would expect to see this:

is first – tangerine
satsuma
is last – mandarin

Instead, I see this:

tangerine
satsuma
mandarin

Can someone double-check my working so I don’t look like a prize ass submitting a bug report for a stupid error? Thank you in advance.

Oh, v4.5.2 (r4197) on Mac OS X, by the way. Same thing happens with v4.5.2 on CentOS 5.

Offline

#5 2012-10-17 11:33:17

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,356
GitHub

Re: article_custom and category matching head scratcher

etc wrote:

I guess if_first_article looks in the scope of article(_custom), not in if_article_category?

Oh, interesting. I’ll try switching the tag order. Thank you, Oleg.

Update: you’re are absolutely correct. I have solved my problem. I ended up tweaking the article_custom call to make it do more work, removed the category checking in the article form and it now works perfectly.

Oleg, thank you so much – I’m very grateful for your advice.

Last edited by gaekwad (2012-10-17 12:24:19)

Offline

Board footer

Powered by FluxBB