Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#31 2012-02-02 23:34:56

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_repeat // Split and repeat.

jakob wrote:

I’d love to see some real-world usage examples for this and the code it produces as I don’t really understand the example above.

Not exactly real life example, but the README.textile has the attribute explained and some examples.

Basically range creates a range of elements, as an array. It takes minimum value, and maximum value and creates a list of those values. In programming languages range is especially cool as it’s freaking fast. It has size limitation (memory), but it’s fast.

Now, let’s say you wanted to build page numbers of some sorts. Nine pages, nine links.

<txp:rah_repeat range="1, 9, 1" break=", "><txp:rah_repeat_value /></txp:rah_repeat>

Returns: 1, 2, 3, 4, 5, 6, 7, 8, 9

Or you wanted to print out alphabet (just basic a-z, it doesn’t support anything else).

<txp:rah_repeat range="a, z, 1" break=", "><txp:rah_repeat_value /></txp:rah_repeat>

Returns: a, b, c, d, [...]

Huh, but there are three parameters, that anonymous 1. It’s step. You bad at math, need every fourth integer:

<txp:rah_repeat range="12, 24, 4" break=", "><txp:rah_repeat_value /></txp:rah_repeat>

Returns: 12, 16, 20, 24

It’s doesn’t do that much. It just creates list of numbers or characters automatically, from min to max. Might be useful for iterating over something multiple times, or to generate page links or something else that needs known integers. Honestly speaking, If it weren’t so easy to add (adding no new code), I wouldn’t have added it. But as it is, well, why not.

Last edited by Gocom (2012-02-02 23:36:08)

Offline

#32 2012-02-03 07:37:37

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,228
Website GitHub

Re: rah_repeat // Split and repeat.

Thanks for the infos. I groked the range attribute and step var fairly easily but the combination example had me flummoxed. Your infos on github (excellent by the way) filled me in, although I’m still a bit confused by the above example:

<txp:rah_repeat range="0,10">
	<txp:rah_repeat_value />:
	<txp:rah_repeat value="00,66,aa,ff"><txp:rah_repeat_value /></txp:rah_repeat>
</txp:rah_repeat>

… which, as far as I can tell, returns 0: 0066aaff 1: 0066aaff 2: 0066aaff 2: 0066aaff .... Now I just need to think of somewhere where that kind of pattern might be useful.


TXP Builders – finely-crafted code, design and txp

Offline

#33 2012-02-03 07:56:09

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,228
Website GitHub

Re: rah_repeat // Split and repeat.

Off Topic: Jukka, your new github repo is most informative and you have a couple of things in there I’d not seen before that look like they could be useful as potential more flexible or more secure alternatives for other much-used plugins. I’m thinking of rah_flat (for cnk_versioning?), rah_backup (for rss_db_admin?) and rah_gps (for adi_gps). Whenever you get the time, I’d love to see some more infos if only to hear whether they are release-ready.

Last edited by jakob (2012-02-03 08:55:00)


TXP Builders – finely-crafted code, design and txp

Offline

#34 2012-02-03 08:04:15

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_repeat // Split and repeat.

jakob wrote:

which, as far as I can tell, returns

Yes.

Now I just need to think of somewhere where that kind of pattern might be useful.

I have no idea. I was just replying to Julián’s question, without actually even knowing in which order the iteration should be executed. More suitable realization might be:

<txp:rah_repeat range="0,10">
	<txp:variable name="i">
		<txp:rah_repeat_value />
	</txp:variable>

	<txp:rah_repeat value="00,66,aa,ff">
		<txp:variable name="i" />: <txp:rah_repeat_value />
	</txp:rah_repeat>
</txp:rah_repeat>

Which returns 0 : 00 0: 66 0: aa 0: ff 1: 00 1: 66 ....

Or perhaps:

<txp:rah_repeat value="00,66,aa,ff">
	<txp:variable name="i">
		<txp:rah_repeat_value />
	</txp:variable>

	<txp:rah_repeat range="0, 10">
		<txp:variable name="i" />
	</txp:rah_repeat>
</txp:rah_repeat>

Which returns 00 00 00 00 00 ... 66 66 66 66 66 ... aa aa.

Last edited by Gocom (2012-02-03 08:06:12)

Offline

#35 2012-02-03 13:10:18

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

Re: rah_repeat // Split and repeat.

Regarding the example, it was just a dummy one, a non-sense at all.
I did something similar while wireframing a website that allowed me to generate some placeholder thumbnails on the fly with different colors (using placehold.it/).

<txp:rah_repeat value="00,66,aa,ff,00,66,aa,ff,00,66,aa,ff,00,66,aa,ff">
  <img src="http://placehold.it/100x100/e1bb<txp:rah_repeat_value />/" />
</txp:rah_repeat> 

At the time I wrote it, I thought that a range="12" or times="12" attribute would have helped in avoiding the long list of repeated values. Then, Gocom provided it :) (although, as he make it clear, both can’t be used in the same rah_repeat tag).


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#36 2012-02-25 08:13:41

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_repeat // Split and repeat.

jakob wrote:

I’d love to see some more infos if only to hear whether they are release-ready.

Super-late reply, I know. I didn’t originally see your post (sorry, I wasn’t ignoring you). Fun times skimming through the forum (I didn’t google myself or anything ha-ha — truth is that I actually did google rah_backup — I’m one of those idiots that use google to open web pages).

Well, so, there is a refactoring of Rah website going (as we know it as rahforum.biz in it’s current form). Once that is done, some of the plugin will be released there as usual in compiled package format. For example rah_backup will be released as a normal plugin in the usual manner and is easy to notice from .org and forum spam.

Rah_backup it’s current state it’s stable, but it might not be good idea to use; it’s dev branch after all. I know that the next push will change the code a bit and drop number of preferences (useless ones to stream line it), making the code OOP.

Other projects as rah_gps, rah_global, mck_login are patches/forks. Most of the time one time deals. Will likely never be updated or compiled as installable packages. Adi updated adi_gps, so that there too.

Rah_flat on the other hand is very complicated plugin. It will be released as git repo, and that is probably it. First stable release will be the v0.1 tag that comes in sometime 2012. I’m very eager to not put out any forum topic for it either (it can be rather dangerous plugin for “end-users” — it can suck the single copy of the database). Cnk_version has eated my database, and I’m not willing to feed lions yet.

One thing you may have noticed that there are plugins missing from GitHub. Except for few, those missing ones are dropped projects. As the new Rah site goes up, they won’t be part of it as they are now. Instead you will be greeted with deprecated notices, instructions and alternatives, and a realllllyyyy tiny download button for those that do not fear germs.

It may seem that a lot have changed, but that just make up. The difference is that I’m using git instead of SVN (I don’t have a soul), and that the repository is public. Now there is easy to use issue tracker too (GitHub is amazing). Well kept secret (or is it? :wink:) is that plugins like rah_backup or new improved rah_post_versions in reality were started while ago. Maybe as far ago as a year.

Offline

#37 2012-08-24 23:09:21

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_repeat // Split and repeat.

Rah_repeat v0.8 is out. This updated concentrates making things easier for all of us. Changelog:

  • Fixed: made the sort attribute’s direction optional.
  • Added: exclude can now take and exclude empty strings ("") and zeros (0).
  • Added: range attribute. Allows generating automated lists (range="min, max, step").
  • Added: assign attribute. Allows extracting values as variables.
  • Added: escape attribute to <txp:rah_repeat_value />.
  • Added: Support for natural ordering (sort="natural").
  • Changed: Now trim is enabled by default. Previously values weren’t trimmed from white-space by default.
  • Changed: Renamed locale sorting option to LOCALE_STRING.
  • Changed: Order can be reversed with out re-sorting by using sort="desc".
  • Now requires PHP 5.2 (or newer).

See the release article for introduction to the new features, or jump directly to the docs and download here.

Offline

#38 2012-08-25 12:50:04

etc
Developer
Registered: 2010-11-11
Posts: 5,689
Website GitHub

Re: rah_repeat // Split and repeat.

I’m getting a weird issue with range (txp 4.4.1 and php 5.3.10 on wamp): whatever values I use, e.g.

<txp:rah_repeat range="4,100" wraptag="p" break=",">
	<txp:rah_repeat_value />
</txp:rah_repeat>

or


<txp:rah_repeat range="a,z" wraptag="p" break=",">
	<txp:rah_repeat_value />
</txp:rah_repeat>

it outputs 0 , 1 , ... , 10.

Offline

#39 2012-08-25 18:49:25

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_repeat // Split and repeat.

Thanks for the report, Oleg. It’s fixed. It was the array_merge I used to make sure there is a third parameter set. Well, It does recalculate numeric indexes.

Offline

#40 2012-08-25 18:59:40

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_repeat // Split and repeat.

Rah_repeat version v0.8.1 is out. Fixes the range issue.

More info and downloads

Offline

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

photonomad
Member
Registered: 2005-09-10
Posts: 290
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: 5,689
Website GitHub

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: 290
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
Developer Emeritus
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: 110

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

Board footer

Powered by FluxBB