Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#41 2012-10-16 18:54:42

photonomad
Member
Registered: 2005-09-10
Posts: 289
Website

Re: rah_repeat // Split and repeat.

Is there any way to sort by variable with rah_repeat? I’m not 100% sure that I understand rah_repeat’s sort features. In the example below, each data set is a listing and one of the value/variables in each set is a date/time (or lack thereof). I would like to order each “listing” by this date/time value if possible.

Here is a simplified version of my code:

<h1>Recently Updated Listings:</h1>
<txp:variable name="all_listings" value='<txp:article_custom section="section_name"><txp:custom_field name="customfieldname" escape="" /></txp:article_custom>' />
<txp:rah_repeat value='<txp:variable name="all_listings" />' delimiter="~||~">
<txp:rah_repeat value='<txp:rah_repeat_value />' delimiter="~|~" assign="field1, field2, field3, update_date" sort="I don't think I can use sort to do want I'd like to do?"/>
	<txp:if_variable name="update_date" value=""><txp:else /><li><txp:variable name="field1" /></li>
</txp:rah_repeat>

Each listing contains 4 values as follows:
field1~|~field2~|~field3~|~update_date~||~

Example content (first set does not contain an update_date):
title field1~|~description field2~|~something else field3~|~~||~another listing title field1~|~this other listing description field2~|~something else for this listing field3~|~2012/10/16 8:51:37~||~the listing title field1~|~the listing desc field2~|~something else for this listing field3~|~2012/06/11 12:20:37~||~another title field1~|~another description field2~|~another something field3~|~2011/02/14 3:47:15~||~

Thanks in advance for any thoughts or suggestions!

Offline

#42 2012-10-16 20:37:04

etc
Developer
Registered: 2010-11-11
Posts: 4,079
Website

Re: rah_repeat // Split and repeat.

Maybe it will be easier to sort listings by SUBSTRING_INDEX in <txp:article_custom />?

Offline

#43 2012-10-16 20:47:21

photonomad
Member
Registered: 2005-09-10
Posts: 289
Website

Re: rah_repeat // Split and repeat.

Thanks for the suggestion, etc. I’m going to have to study up on SUBSTRING_INDEX.

Offline

#44 2013-04-23 09:28:23

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_repeat // Split and repeat.

v1.0.0 released. Changes:

  • Fixed: Return a empty string instead of NULL byte on halt.
  • Added: form attribute.
  • Added: index attribute to the rah_repeat_value tag.
  • Now requires Textpattern 4.5.0 or newer.

More info and downloads

Offline

#45 2016-04-13 19:37:58

lazlo
Member
Registered: 2004-02-24
Posts: 104

Re: rah_repeat // Split and repeat.

Hi Jukka

This is a wonderful plugin and I use it to great effect but …

First Problem.

Do you think rah_repeat will get a proper “Alpha” sort where Lower case “b” and Upper case “B” are treated the same? As it stands now the “string” sorts all upper case first, then lower case. Is there another solution?

Second Problem.

I am having a bit of problem with a single white space character being inserted during rah_repeat.

This code:

<txp:rah_repeat  value='<txp:custom_field name="Contributors_Group"/>' delimiter="~||~">
<txp:rah_repeat  value='<txp:rah_repeat_value />' delimiter="~|~" assign="onix_code,contributor_role,contributor_full_name,contributor_full_name_reversed, contributor_name_before_key,contributor_key_name,contributor_latin_1,contributor_URL, contributor_country"/>
<txp:if_variable name="onix_code" value="A02">
<txp:variable name="contributor_full_name"/></txp:if_variable>
</txp:rah_repeat>
</txp:rah_repeat>

When iterated over this data set (or any data set like this).

A01~|~By~|~John MacLachlan Gray~|~Gray, John MacLachlan~|~Gray~|~John MacLachlan~|~John MacLachlan Gray~|~john-maclachlan-gray~|~CA~||~
A02~|~With~|~Eric Peterson~|~Peterson, Eric~|~Peterson~|~Eric~|~Eric Peterson~|~eric-peterson~|~CA~||~

The variable <txp:variable name=“contributor_full_name”/> shows “ Eric Peterson” not “Eric Peterson”

It seems that you are adding a white space seperator for list purposes and it is at the front?

Third Problem (related to Second Problem I imagine).

If I insert a break=“br” into

<txp:rah_repeat break="br" value='<txp:custom_field name="Contributors_Group"/>' delimiter="~||~">

The result is “<br /> Eric Peterson” not “Eric Peterson<br />.
The final name in a list that iterates over many of these datasets doesn’t have a <br /> after it but the first one has a <br /> precede it.

Last edited by lazlo (2016-04-13 20:12:48)

Offline

#46 2016-04-14 03:20:12

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

Re: rah_repeat // Split and repeat.

Jukka gone.

Gone, daddy… gone.

Offline

#47 2016-04-14 05:38:06

lazlo
Member
Registered: 2004-02-24
Posts: 104

Re: rah_repeat // Split and repeat.

mrdale wrote #298605:

Jukka gone.

Gone, daddy… gone.

Oh, does that mean rah plugins are orphaned?

Offline

#48 2016-04-14 16:05:42

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,036
Website

Re: rah_repeat // Split and repeat.

Oh, does that mean rah plugins are orphaned?

Kind of. They all / mostly work and they are pretty invaluable but Jukka’s been AWOL for a long while on seemingly all internet channels with his gocom handle. His site went down a while ago with a server/txp-version error, then returned after some weeks, so someone must have repaired something…

I am having a bit of problem with a single white space character being inserted during rah_repeat

Re: your question: Does your space disappear if you don’t have a newline in there? There is the trim="1" attribute, but that is set by default and I think applies only to the values in the attribute and not the output. If you have no luck with that, you can trim the output itself “manually” by wrapping your output in <txp:smd_wrap>…</txp:smd_wrap> or <txp:rah_function call="trim">…</txp:rah_function>.

The result is “<br /> Eric Peterson” not “Eric Peterson<br />.

The <br> appearing before and not after your value has – I think – to do with the fact that you have the break value in the outer rah_repeat tag. That will add a <br> at the ~||~ delimiter, and that comes before your if_variable tag does its checking… and as you are using rah_repeat_value as an attribute for the nested instance, it does trigger the repeat counter and therefore outputs a <br>.


TXP Builders – finely-crafted code, design and txp

Offline

#49 2016-04-14 22:58:42

lazlo
Member
Registered: 2004-02-24
Posts: 104

Re: rah_repeat // Split and repeat.

jakob wrote #298617:

The <br> appearing before and not after your value has – I think – to do with the fact that you have the break value in the outer rah_repeat tag. That will add a <br> at the ~||~ delimiter, and that comes before your if_variable tag does its checking… and as you are using rah_repeat_value as an attribute for the nested instance, it does trigger the repeat counter and therefore outputs a <br>.

This does explain the <br> position. If I have the <br> on the innner rah_repeat the repeat counter triggers and outputs a <br> for every line parsed. I end up with:

<br>
<br>
<br>
<br>
Eric Peterson <br>
<br>
<br>
John Peterson <br>
<br>
<br>
<br>

This explains the space using the same logic as it only seems to happen in these nested situations. The space does appear regardless of new line. “ Eric Peterson John Peterson Tim Peterson “ is what is outputted in the nested call without the <br>. By default I think rah_repeat adds a trailing space after the delimiter even if Trim = "1" is on. Or somewhere it is picking up a single white space in my code as it iterates, which I really have tried to find unsuccessfully.

Thanks for the help Jakob, that clear explanation was very helpful.

Offline

#50 2016-04-15 09:14:22

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,036
Website

Re: rah_repeat // Split and repeat.

I can’t see anything in the rah_repeat code that would indicate it’s adding a space. The code does show that the in-built trim function only trims spaces around the values between the delimiters.

To determine where the space is coming from, temporarily add some markers to your code, e.g. <txp:if_variable name="onix_code" value="A02">|<txp:variable name="contributor_full_name"/>|</txp:if_variable> to determine if the space is already in the variable. If not (which I suspect), then shift the markers straight after/before the opening and closing inner rah_repeat tags, e.g. <txp:rah_repeat … >| … your code … |</txp:rah_repeat>, and if not there either, then shift them just inside the outer rah_repeat tags…

If you discover it is the other line breaks in your code, you can then write your tidy code all bunched together with no line breaks at all, e.g.:

<txp:rah_repeat value='<txp:custom_field name="Contributors_Group"/>' delimiter="~||~"><txp:rah_repeat value='<txp:rah_repeat_value />' delimiter="~|~" assign="onix_code,contributor_role,contributor_full_name,contributor_full_name_reversed, contributor_name_before_key,contributor_key_name,contributor_latin_1,contributor_URL, contributor_country"><txp:if_variable name="onix_code" value="A02"><txp:variable name="contributor_full_name"/></txp:if_variable></txp:rah_repeat></txp:rah_repeat>

or
, to maintain readability, you can use rah_function call="trim" to trim the output ‘manually’, e.g.

<txp:rah_repeat value='<txp:custom_field name="Contributors_Group"/>' delimiter="~||~"><txp:rah_function call="trim">

  <txp:rah_repeat value='<txp:rah_repeat_value />' delimiter="~|~" assign="onix_code,contributor_role,contributor_full_name,contributor_full_name_reversed, contributor_name_before_key,contributor_key_name,contributor_latin_1,contributor_URL, contributor_country">
    <txp:if_variable name="onix_code" value="A02"><txp:variable name="contributor_full_name"/></txp:if_variable>
  </txp:rah_repeat>

</txp:rah_function></txp:rah_repeat>

EDIT: another possibility: I noticed when copy/pasting the code that you have a closing slash at the of the inner tag that shouldn’t be there after … contributor_country"/>. Maybe that’s the culprit?


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB