Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[solved x 2] tricky problem: format article custom fields into a table
TXP Freakin Geniuses start your engines.
I want to turn the following articles…
- title:article A / cf_vintage:2007 / cf_release:syrah / cf_action:dump
- title:article B / cf_vintage:2007 / cf_release:merlot / cf_action:hold
- title:article C / cf_vintage:2007 / cf_release:viognier / cf_action:dump
- title:article D / cf_vintage:2008 / cf_release:merlot / cf_action:drink-hold
- title:article E / cf_vintage:2008 / cf_release:syrah / cf_action:hold
- title:article F / cf_vintage:2006 / cf_release:syrah / cf_action:drink
- title:article G / cf_vintage:2008 / cf_release:viognier / cf_action:drink
- title:article H / cf_vintage:2009 / cf_release:viognier / cf_action:drink
into the following table.
Release 2006 2007 2008 2009 merlot - hold drink-hold - syrah drink dump hold - viognier - dump drink drink
the difficulty is that not every vintage has every release, so it’s hard to format empty cells.
Last edited by mrdale (2012-07-12 06:12:17)
Offline
#2 2012-07-03 20:46:30
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: [solved x 2] tricky problem: format article custom fields into a table
Very nice :) Having a go at it now (but don’t hold your breath…)
Offline
#3 2012-07-03 21:14:02
- milosevic
- Member

- From: Madrid, Spain
- Registered: 2005-09-19
- Posts: 390
Re: [solved x 2] tricky problem: format article custom fields into a table
Perhaps this will fit your requirement. Not sure if I understand 100% your requirements:
<td>
<txp:custom_field name="cf_release"/>
</td>
<td>
<txp:if_custom_field name="cf_vintage" value="2006">
<txp:custom_field name="cf_action"/>
<txp:else/>-</txp:if_custom_field>
</td>
<td>
<txp:if_custom_field name="cf_vintage" value="2007">
<txp:custom_field name="cf_action"/>
<txp:else/>-</txp:if_custom_field>
</td>
<td>
<txp:if_custom_field name="cf_vintage" value="2008">
<txp:custom_field name="cf_action"/>
<txp:else/>-</txp:if_custom_field>
</td>
<td>
<txp:if_custom_field name="cf_vintage" value="2009">
<txp:custom_field name="cf_action"/>
<txp:else/>-</txp:if_custom_field>
</td>
<txp:rocks/>
Offline
Re: [solved x 2] tricky problem: format article custom fields into a table
almost, but the vintages are dynamic.
Offline
#5 2012-07-03 21:38:18
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: [solved x 2] tricky problem: format article custom fields into a table
mrdale wrote:
almost, but the vintages are dynamic.
I think we need (a lot of) variables. (Still trying… not quite there yet.)
Offline
Re: [solved x 2] tricky problem: format article custom fields into a table
or a lot of nesting… also working.
Offline
#7 2012-07-03 22:16:48
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: [solved x 2] tricky problem: format article custom fields into a table
If the vintages are dynamic, the number of columns can vary, right? So you could have four columns, or twenty, or whatever. The table head can be done, but I don’t see a way to determine the number of cells needed for the content. I suppose you can’t use a custom field for each vintage?
Offline
Re: [solved x 2] tricky problem: format article custom fields into a table
your assumptions are correct. I think I’m closing in on it tho.
Offline
Re: [solved x 2] tricky problem: format article custom fields into a table
OK, I did it, but I discovered that my old standby chh_if_data doesn’t work inside smd_each
Mighty chuffed… (requires smd_each)… see the solution here»
Last edited by mrdale (2012-07-04 04:05:59)
Offline
#10 2012-07-04 07:30:21
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: [solved x 2] tricky problem: format article custom fields into a table
mrdale wrote:
Mighty chuffed… (requires smd_each)… see the solution here»
Nice! I really like this kind of tag use :) I was halfway there last night, trying to do it without plugins. But I don’t think that is possible ;)
Offline
Re: [solved x 2] tricky problem: format article custom fields into a table
I was wondering if <txp:chh_if_data> could be replaced with <txp:if_custom_field name="wine_cellaring">
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#12 2012-07-04 13:22:09
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,319
Re: [solved x 2] tricky problem: format article custom fields into a table
There’s one thing that makes my wires melt (I just “beautified” the code to make it more readable):
<txp:variable name="vintages">
<txp:custom_field name="wine_vintage" />
<txp:if_first_article>
<txp:else/>
,
</txp:if_first_article>
<txp:variable name="vintages" />
</txp:variable>
Why you put the variable inside itself, what is its content after doing so?
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: [solved x 2] tricky problem: format article custom fields into a table
Uli, he adds the variable to itself, at the same time it adds the value of the custom field, making a list of values.
If the first value of the variable is “dog”, and then the custom field value is “cat”, the variable will end up being “cat, dog”. On each iteration (over textpattern articles), the variable gets a new value.
Offline
#14 2012-07-04 14:07:04
- uli
- Moderator

- From: Cologne
- Registered: 2006-08-15
- Posts: 4,319
Re: [solved x 2] tricky problem: format article custom fields into a table
Ah, thanks, Julián, didn’t know that you can do that with a variable, thought it’d lead to a short circuit.
And b) had forgotten we’re in an article_custom loop, thus it isn’t the only call of this variable.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: [solved x 2] tricky problem: format article custom fields into a table
A glass of 2007 Malbec would make it all seem better.
Offline