Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-07-03 18:07:18

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

[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…

  1. title:article A / cf_vintage:2007 / cf_release:syrah / cf_action:dump
  2. title:article B / cf_vintage:2007 / cf_release:merlot / cf_action:hold
  3. title:article C / cf_vintage:2007 / cf_release:viognier / cf_action:dump
  4. title:article D / cf_vintage:2008 / cf_release:merlot / cf_action:drink-hold
  5. title:article E / cf_vintage:2008 / cf_release:syrah / cf_action:hold
  6. title:article F / cf_vintage:2006 / cf_release:syrah / cf_action:drink
  7. title:article G / cf_vintage:2008 / cf_release:viognier / cf_action:drink
  8. 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

#4 2012-07-03 21:28:36

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

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

#6 2012-07-03 21:41:48

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

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

#8 2012-07-03 23:59:15

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

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

#9 2012-07-04 03:50:38

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

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

#11 2012-07-04 08:49:35

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,395
Website GitHub Mastodon Twitter

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

#13 2012-07-04 13:29:57

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

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.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

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

#15 2012-07-04 16:30:52

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 335
Website

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

Board footer

Powered by FluxBB