Textpattern Forum

You are not logged in. Register | Login | Help

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

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 4,893
Website

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 | neme-imca.org | hblack.net | LABS

Offline

#12 2012-07-04 13:22:09

uli
Moderator
From: Cologne/Köln
Registered: 2006-08-15
Posts: 3,014

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
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 2,975
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/Köln
Registered: 2006-08-15
Posts: 3,014

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: 113
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

#16 2012-07-04 17:03:13

mrdale
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,050
Website

Re: [solved x 2] tricky problem: format article custom fields into a table

colak wrote: I was wondering if <txp:chh_if_data> could be replaced with <txp:if_custom_field name="wine_cellaring">

good call you crazy Cypriot. Updated the solution to add classes for odd/even rows and other stuff.

Offline

#17 2012-07-04 17:29:40

maniqui
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 2,975
Website

Re: [solved x 2] tricky problem: format article custom fields into a table

<txp:if_custom_field name="wine_cellaring" value="">—<txp:else/><txp:custom_field name="wine_cellaring" /></txp:if_custom_field>

Want to shorten that even more?

You could try:

<txp:custom_field name="wine_cellaring" default="-" />

(yeah, txp:custom_field accepts a default attribute, crazy, isn’t it?)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#18 2012-07-04 19:35:49

Els
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,380
Website

Re: [solved x 2] tricky problem: format article custom fields into a table

I think we need a Wall of Fame for code. This specimen definitely deserves a place there!


<txp:Els /> ;)
Tag Reference | Unexpected behaviour? Check the tag trace | Still no clue? Check the names of your custom fields

Offline

#19 2012-07-04 20:37:59

Gocom
Developer
Registered: 2006-07-14
Posts: 4,471
Website

Re: [solved x 2] tricky problem: format article custom fields into a table

That code can become bit of nightmare when it comes to performance and the amount of resource it uses. For starters, it generates 4 MD5 hashes for each article it displays. While calculating a single md5 hash doesn’t take much, on a site that has full set of 999 articles published in section releases it will generate 3996 MD5 hashes in total on each page load. On a as large site it can also use up to 1002 SQL queries, and there is quite a bit of copying and processing going on too.

uli wrote:

Ah, thanks, Julián, didn’t know that you can do that with a variable, thought it’d lead to a short circuit.

No, because variables store just results, not code or references. If it worked like a Form template or an article field, and stored and evaluated code, then in that situation you would have a circular reference since the instance of variable tag would call the variable tag again. But since it stores just the value the variable returned on the last call, fortunately no.

Last edited by Gocom (2012-07-04 20:44:47)


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#20 2012-07-04 22:45:52

mrdale
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,050
Website

Re: [solved x 2] tricky problem: format article custom fields into a table

Gocom wrote: That code can become bit of nightmare

atta boy… feel free to refactor that for me ;)

Manequi wrote: Want to shorten that even more?

way cool. great to know That’ll save me 5% on my keyboard’s life. I’ll try it. BUT interestingly enough the else part of that doesn’t actually work in the code. no idea why.

Last edited by mrdale (2012-07-04 22:47:23)

Offline

Board footer

Powered by FluxBB