Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2009-11-30 07:34:37

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

Re: rah_repeat // Split and repeat.

the_ghost wrote:

I think trimming and deleting lonely delimiters is rather useful. Imaging we create list of values and get such string: Minsk, Tokio, New-Yourk, Oslo, Helsinki, – in such way we will get 6 repeatings, instead of 5. To eliminate this we have to use if_last logic while geenrating string.

But it should be optional, and those can be done with plain TXP markup. Those aren’t required in the plugin itself. So, where optional attributes are nice, they make the plugin slower.

Still don’t get what this should do:

$delim_length = strlen($delimiter);
		if (substr($value, -$delim_length) == $delimiter) {
			$value = substr($value, 0, -$delim_length);
		}

You do know that the value will be empty after the trim and empty values can be nullified by checking if the value is empty.

Therefor we get:

<txp:rah_repeat value="foo, bar">
	<txp:rah_function call="trim">
		<txp:rah_repeat_value />
	</txp:rah_function>
</txp:rah_repeat>

Wich we can put inside <txp:variable/> and check if it exists. If it doesn’t we do none.

And another usful tag, just thought about it – rah_if_last/first – will be very good :)

Nice. rah_repeat_if_last/first are things that we might see in upcoming update. Thank you for good request.

For those that need _if_first right now, you can currenlty use offset to simulate that. And if_last is doable with if_variable.

Offline

#14 2009-11-30 07:51:00

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: rah_repeat // Split and repeat.

A little more explanation:

$delim_length = strlen($delimiter); // get the length of delimiter (what if we set 'zzz' as delimiter? This can happen :)
		if (substr($value, -$delim_length) == $delimiter) { // cut the last 3 chars from string and check if they are delim (if delim was ',' - we would cut 1 char)
			$value = substr($value, 0, -$delim_length); // return string without last 3 chars, because they was unused delimiter
		}

That’s all.


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#15 2009-11-30 08:13:53

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

Re: rah_repeat // Split and repeat.

the_ghost wrote:

A little more explanation:

Thanks, but I didn’t mean you need to explain what it does. I know what it does, but I’m wondering why it is there. You can do it with empty check. As I said:

You do know that the value will be empty after the trim and empty values can be nullified by checking if the value is empty.

Offline

#16 2009-11-30 09:19:03

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

Re: rah_repeat // Split and repeat.

Released version 0.4 of rah_repeat. Changelog:

  • Fixed: now returns old parent global, if two tags are used inside each other, instead of defining it empty.
  • Added: <txp:rah_repeat_if_first>.
  • Added: <txp:rah_repeat_if_last>.

More info and downloads

Offline

#17 2010-05-08 21:37:34

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

Re: rah_repeat // Split and repeat.

Released an update. Version 0.5 adds some new possiblities.

  • Added attribute: duplicates.
  • Added attribute: sort.
  • Offset’s default value is now zero (0) instead of unset.

From this version onwards, you can feed the tag duplicate values and it will remove them if you set duplicates attribute to 1.

The new sorting allows you to rearrange the values. For example if you feed the tag image IDs in random order, and you want them in lowest ID to highest, now it’s possible with the sort attribute.

Plugin page and downloads

Offline

#18 2010-05-09 03:20:43

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

Re: rah_repeat // Split and repeat.

Meds here, v0.6 landed shelves.

  • Added attribute: exclude. Exclude is the racist attribute, always excluding.
  • Fixed unworking <txp:rah_repeat_if_last> tag caused by v0.5 update. Duct tape!

Aids, fix and less crappy jokes

Offline

#19 2010-05-17 14:32:15

aswihart
Member
From: Pittsburgh, PA
Registered: 2006-07-22
Posts: 345
Website

Re: rah_repeat // Split and repeat.

I’m trying to use this with adi_calc, letting adi_calc dynamically change values with each repeat, so I don’t really have a use for the value attribute in rah_repeat. But, it seems I have to plug in some values in the value attribute, greater than or equal to the limit attribute, in order for it to do it’s job: repeat. Is that the intended behavior?

Offline

#20 2010-05-18 04:00:54

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

Re: rah_repeat // Split and repeat.

aswihart wrote:

Is that the intended behavior?

Yes it is.

Offline

#21 2010-10-01 04:32:50

radneck
Plugin Author
Registered: 2005-07-03
Posts: 109

Re: rah_repeat // Split and repeat.

Gocom wrote:

Enjoy pancakes:
Oh, sir, syrup?
Pardon me, your menu is odd. Where’s my donkey?
Wohoo, pony donkey ride!

Offline

#22 2010-10-01 16:59:11

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

Re: rah_repeat // Split and repeat.

cain-mi, you are reading about awesomish plugin that ships with nonexistent free pony donkey and butler, doh.

Offline

#23 2010-11-07 11:00:03

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

Re: rah_repeat // Split and repeat.

This plugin gets better every time I use it! Here’s an odd question: how might I split a string according to more than one break ‘trigger’?

The use case is to find out if there are more than one items in a text string and change the header accordingly from singular to plural. I have it working as I want it with break=",", e.g. “cats, dogs and snakes” results in a plural heading, but it doesn’t catch the case “cats and dogs” because has no comma in it. What’d like to do is something like break=",|and" but I’ve no idea whether that works. Any other suggestions?

<txp:variable name="check_multi_items" 
              value='<txp:rah_repeat value=''<txp:custom_field name="species" />'' break="," offset="1" limit="1"><txp:rah_repeat_value /></txp:rah_repeat>' />
   <txp:if_variable name="check_multi_items" value="">
      Singular heading:
   <txp:else />
      Plural heading:
   </txp:if_variable>

TXP Builders – finely-crafted code, design and txp

Offline

#24 2010-11-07 11:24:49

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

Re: rah_repeat // Split and repeat.

jakob wrote:

What’d like to do is something like break=”,|and” but I’ve no idea whether that works. Any other suggestions?

Do you mean, you want it to split the string from both and and ,, or should it form the results with “and”. The break attribute is used to form the resulting list, while delimiter is used to split.

If you want to do split with multiple values, you might be able to nest two tags:

<txp:rah_repeat delimiter="," value='<txp:rah_repeat delimiter="and" value="dog, cat and lemon" break=","><txp:rah_repeat_value /></txp:rah_repeat>'><txp:rah_repeat_value /></txp:rah_repeat>

The first call splits with and while the second one does the commas.

If you want to have and in the resulting list, you could use <txp:rah_repeat_if_last /> conditional. For example:

<txp:rah_repeat value="cat,dog,lemon">
	<txp:rah_repeat_if_first>
		<txp:else />
			<txp:rah_repeat_if_last>
				and
			<txp:else />
				,
			</txp:rah_repeat_if_last>
	</txp:rah_repeat_if_first>
	<txp:rah_repeat_value />
</txp:rah_repeat>

That nested if_first/if_last mess is there because if there is only one value, it’s both, the first and the last. The examples are untested, not sure if the actually work. Be warned ;-)

PS. performance wise the plugin isn’t the best solution for searching needle from haystack as the plugin does much more. It’s awfully slow for just that compared to slimmed down solution. If you just want to know if the custom field has and/comma in there, I would suggest using plain PHP and strpos(). But if you are using rah_repeat for something else and returning the results then go ahead, it’s not bad solution for that at all ;-)

Last edited by Gocom (2010-11-07 11:32:04)

Offline

Board footer

Powered by FluxBB