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,214
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: 389

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,214
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,214
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,214
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,214
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: 8,630
Website GitHub 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.org | hblack.net | State Machines | NeMe @ github
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,241

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

Board footer

Powered by FluxBB