Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#49 2012-07-19 14:25:41

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

Re: rah_function // Every PHP function is a tag

And updated to v0.6. Brings number of corrections to the documentation and my caveman English. All thanks to Ralitza.

Offline

#50 2012-07-19 15:14:32

WebKat
Member
Registered: 2007-01-16
Posts: 301

Re: rah_function // Every PHP function is a tag

Hi and thanks for developing this very useful plugin. Unfortunately for me I don’t know how to code PHP and that seems to put me at a disadvantage for figuring out how the syntax works to make rah_function do what I need it to do. How open are you to emails asking questions like “how do I write this tag to make it do X”? I would generally come here and ask in the thread first, but sometimes the response time is…uh… long.



WebKat

Offline

#51 2012-07-19 16:10:52

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

Re: rah_function // Every PHP function is a tag

Kat,

Please, present your general How-to question here or on the appropriate forum area. This allows community members other than me to answer your questions and contribute with better solutions. I will chime in to questions presented here or anywhere else on the forums when and if I have anything to say or the necessary time.

Feel free to inform me with issue reports, bugs and likes, but I can’t write code for everyone or answer questions personally. Especially how-to question that demand straight snippets, please don’t. Please. I hope you understand.

Please keep in mind that me personally, in general, do not like to answer with direct snippets. I’m inclined to answer by giving pointers so that the one needing help can learn and then in the future can solve similar problems themselves. For instance, rah_function should be considered as an advanced tool, which requires basic knowledge of scripting languages and some stepping stones along the way. Unless you have that knowledge, the tool can be outright harmful and dangerous as far as security goes.

Last edited by Gocom (2012-07-19 16:14:45)

Offline

#52 2012-07-25 10:24:02

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: rah_function // Every PHP function is a tag

Hi,
I will like to know please how to I split a variable/custom_filed data twice, and build the output with the values.
Split it once by ~||~
and the second time by ~|~

Here’s an example of what I need using <txp:php>,
which I will like to convert it to use your plugin do get more flexibility and let me use other plugins and TXP to build the output.

<txp:article_custom section="schedule" limit="7" sort="Posted asc">

	<txp:variable name="shows_data"><txp:custom_field name="schedule" /></txp:variable>

	<ul>
	<txp:php>
		global $variable;

		// Split all shows
		$variable['shows_data'] = explode('~||~',$variable['shows_data']);

		foreach ($variable['shows_data'] as $show_data){

			// Split each show data
			$show_data = explode('~|~',$show_data);

			$show_id = $show_data[0];
			$show_title = $show_data[1];

			echo '
				<li>
					<span class="id">'.$show_id.'</span>
					<span class="title">'.$show_title.'</span>
				</li>
			';

		}
	</txp:php>
	</ul>

</txp:article_custom>

so what we got here?
A list of articles, each contains a data from a custom-field name “schedule”,
which contains a list of shows, and it’s own data, like a list of articles and they data.
I’m taking the main custom-filed data and insert it into a txp-variable to be able to use it inside <txp:php>.
Then I split the data once by ~||~ to separate each show/article,
and split it again by ~|~ to get each show/article own data,
then I’m able to play with it and build my output and echo it.

So I want to do just the same but with your plugin,
Now I don’t understand how do I get the values from the split please?

<txp:article_custom section="schedule" limit="7" sort="Posted asc">

	<txp:rah_function call="explode" delimiter="~||~" values='<txp:custom_field name="schedule" />'>
		What next?
		How do I get the "this" value to split it again,
		And how do I get each value from the array please as "this[0]" "this[1]" "this[2]" ...
	</txp:rah_function>

</txp:article_custom>

Offline

#53 2012-07-25 12:07:59

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

Re: rah_function // Every PHP function is a tag

I guess you need rah_repeat

Offline

#54 2012-07-25 12:19:12

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: rah_function // Every PHP function is a tag

etc wrote:

I guess you need rah_repeat

It looks so pretty! :)
Thanks!

But isn’t rah_function should replace all the other specific rah_+a-php-function plugins?

Offline

#55 2012-07-25 13:52:20

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

Re: rah_function // Every PHP function is a tag

etc wrote:

I guess you need rah_repeat

I would second that. Rah_repeat and smd_each both could be good options for the task.

THE BLUE DRAGON wrote:

But isn’t rah_function should replace all the other specific rah_+a-php-function plugins?

You are correct on that. It even has actually. See the bottom of this page. Rah_repeat isn’t a plugin that is going to be replaced, as it’s not directly just a wrapper for a PHP function.

As rah_function doing this goes, you could probably do this with it, but rah_repleat is probably better suited to the task as noted by etc.

If you were to do it with rah_function you would currently have to use multiple rah_function tags, I suppose. First that creates an array of the data, and then those that slice the values. Using things as the _array prefix, explode, array_slice and implode. E.g.

<!--
	Splits the string. The variable will contain a JSON representation of the array
-->

<txp:variable name="array"><txp:rah_function 
	call="explode" 
	delimiter="~||~" 
	value='<txp:custom_field name="schedule" />'
/></txp:variable>

<!--
	Returns parts from the "array" variable using array_slice and implode
-->

<txp:rah_function 
	call="array_slice, implode" 
	_arrayValue='<txp:variable name="array" />'
	start="0"
	end="1"
/>

<txp:rah_function 
	call="array_slice, implode" 
	_arrayValue='<txp:variable name="array" />'
	start="1"
	end="2"
/>

The current development version of rah_repeat introduces an assign attribute that makes the above much easier. Next version of rah_repeat will be released after TXP 4.5.0 comes out, but the development version can be considered pretty stable too in its current state. It does use a one function only present in dev/4.5.0 tho, which means it technically may need Textpattern dev branch (4.5.0) for full feature support. With the assign attribute the above translates to:

<txp:rah_repeat 
	value='<txp:custom_field name="schedule" />' 
	delimiter="~||~" 
	assign="show_id, show_title" 
/>
<txp:variable name="show_id" />
<txp:varaible name="show_title" />

Last edited by Gocom (2012-07-25 13:54:10)

Offline

#56 2012-07-25 16:35:19

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: rah_function // Every PHP function is a tag

Gocom wrote:

The current development version of rah_repeat introduces an assign attribute that makes the above much easier.

Thanks, I tried to install it but there is no installation code on github, only open PHP code,
So I tried to replace the current v0.7 code with the new code and I’m getting an error,
and did you mean that the current development version also requires TXP4.5 ?, as I’m on 4.4.1.

Am I able to grab each value from the array using v0.7 ?
Something like:

<txp:rah_repeat_value_0 />
<txp:rah_repeat_value_1 />
<txp:rah_repeat_value_2 />
<txp:rah_repeat_value_3 />
<txp:rah_repeat_value_4 />
<txp:rah_repeat_value_5 />
<txp:rah_repeat_value_6 />

Last edited by THE BLUE DRAGON (2012-07-25 16:56:50)

Offline

#57 2012-07-25 17:14:41

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

Re: rah_function // Every PHP function is a tag

THE BLUE DRAGON wrote:

So I tried to replace the current v0.7 code with the new code and I’m getting an error

Replacing the code would work as a installation method as long as you strip out the <?php and ?> tags. You could also use plugin cache directory to load source code files as plugins. What error specifically?

did you mean that the current development version also requires TXP4.5 ?, as I’m on 4.4.1.

Yes. Due to use of new txpspecialchars() (a wrapper/shorthand for htmlspecialchars).

Am I able to grab each value from the array using v0.7 ?

You would have to assign the values as variables if you wish to use the assigning feature. But there is no limitation in number.

It’s possible to directly 1on1 replicate your PHP snippet as rah_repeat loop. Please take a look at the Repeat inside repeat example. Along the lines of:

<txp:rah_repeat value="..." delimiter="~||~">
	<txp:rah_repeat 
		value='<txp:rah_repeat_value />' 
		delimiter="~|~" 
		assign="show_id, show_title, item3, item4, item5" 
	/>
	<txp:variable name="show_id" />
	<txp:variable name="show_title" />
</txp:rah_repeat>

Last edited by Gocom (2012-07-25 17:18:50)

Offline

#58 2012-07-25 17:40:27

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: rah_function // Every PHP function is a tag

Gocom wrote:

You would have to assign the values as variables if you wish to use the assigning feature. But there is no limitation in number.

It’s possible to directly 1on1 replicate your PHP snippet as rah_repeat loop. Please take a look at the Repeat inside repeat example. Along the lines of:

I’m sorry but I don’t quite understand,
Lets forget about the new version, since I’m using TXP 4.4.1 and rah_repeat v0.7, which doesn’t have the new “assign” attribute.
(I have no idea how to update to TXP 4.5 and not even sure if I can do it right now for this project)

Can you please provide an example of how I can get only value #3, or only value #3,#5,#6,#11.
I mean what’s the syntax of your plugin replacement-tags such as the regular <txp:rah_repeat_value /> please?

Offline

#59 2012-07-25 18:06:47

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

Re: rah_function // Every PHP function is a tag

THE BLUE DRAGON wrote:

Can you please provide an example of how I can get only value #3, or only value #3,#5,#6,#11.
I mean what’s the syntax of your plugin replacement-tags such as the regular <txp:rah_repeat_value /> please?

The tag <txp:rah_repeat_value /> outputs the current value split from string specified in value attribute. The tag doesn’t act as replacement tag that can get values other than the current. Rah_repeat doesn’t have replacement tag syntax as smd_each has them.

In v0.7 and older, the plugin concentrates solely on simple looping (aka iteration, repeating). The one and only way to access data is to iterate over it. Extracting parts of a string isn’t possible so to speak. The only thing you can dot to get an individual value other than the current, is to nest rah_repeat tags, iterate and use offset and limit. Please take a look at the Taking advantage of offset and limit and Repeat inside repeat examples in the help file. Both of those example can be used together. Merging those snippets gives you something along the lines of:

<txp:rah_repeat value="..." delimiter="~||~">
	Value1: <txp:rah_repeat
		value='<txp:rah_repeat_value />'
		delimiter="~|~"
		offset="0"
		limit="1"
	><txp:rah_repeat_value /></txp:rah_repeat>

	Value2: <txp:rah_repeat
		value='<txp:rah_repeat_value />'
		delimiter="~|~"
		offset="1"
		limit="1"
	><txp:rah_repeat_value /></txp:rah_repeat>

	Value3: <txp:rah_repeat
		value='<txp:rah_repeat_value />'
		delimiter="~|~"
		offset="2"
		limit="1"
	><txp:rah_repeat_value /></txp:rah_repeat>
</txp:rah_repeat>

Last edited by Gocom (2012-07-25 18:10:15)

Offline

#60 2012-07-25 18:23:25

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: rah_function // Every PHP function is a tag

Gocom wrote:

The only thing you can dot to get an individual value other than the current, is to nest rah_repeat tags, iterate and use offset and limit.

Thanks working great :)

Offline

Board footer

Powered by FluxBB