Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#61 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

#62 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

#63 2012-09-23 21:52:13

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

Re: rah_function // Every PHP function is a tag

Hi Jukka.
Not sure what I’m doing wrong here.
With rah_function v0.6, I’m trying this:

<txp:rah_function call="parse_url" url="http://www.example.com/test/abc" _intcomponent="PHP_URL_PATH" />

I get just http in the output

While this equivalent:

<txp:php>
  echo parse_url("http://www.example.com/test/abc", PHP_URL_PATH);
</txp:php>

correctly outputs /test/abc.

I’ve skimmed over plugin help docs, but couldn’t find a clue. Enlighten me. Thanks. :)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#64 2012-09-24 03:18:46

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

Re: rah_function // Every PHP function is a tag

PHP_URL_PATH is a constant. In the PHP snippet you are using it as such, but in the tag markup it’s considered as a string. In other words, you are passing a literal string of PHP_URL_PATH to the the function instead of the constant’s value. When converted to an integer by the _int prefix, it is passed on as a 0.

Instead of the string and constants name, you could use the constant’s returned value. Which for PHP_URL_PATH is 5. E.g.

<txp:rah_function
	call="parse_url"
	url="http://www.example.com/test/abc"
	component="5"
/>

Adding constant support could be beneficial indeed. So, commit 47d05e3 introduces a _constant prefix and makes using an constant as an attribute possible:

<txp:rah_function _constantAttr="I_LIKE_CHEESE" />

Last edited by Gocom (2012-09-24 03:32:50)

Offline

#65 2012-09-24 04:23:43

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

Re: rah_function // Every PHP function is a tag

PHP docs on parse_url don’t show the returned values for constants. I may have figured it out if docs would have show them :)
Thanks, Jukka.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#66 2013-04-25 09:35:49

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

Re: rah_function // Every PHP function is a tag

v0.7.0 released. Changes:

  • Added: _constant attribute prefix.
  • Added: _assign attribute.
  • Changed to semantic versioning.
  • Released as a composer package.

More info and downloads

Offline

#67 2021-03-09 17:20:35

TheMakmal
New Member
From: KL-MY
Registered: 2021-03-09
Posts: 4
Website

Re: rah_function // Every PHP function is a tag

Hi guys,

Any idea how I could use this to display Tomorrow’s date?
It’s for a food delivery website. Just want to keep showing the date of the next day.

(I used to do this via <txp:php /> but for some reason I can’t seem to save my page/forms with certain inline php/js scripts. I suspect my hosting made some security changes. So am just wondering if I could use this plugin instead since it seem this is a better approach. Also, am a designer here. Can’t really code much beyond front-end things :)

Offline

#68 2021-03-09 19:28:53

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

Re: rah_function // Every PHP function is a tag

Hi,

welcome (back?) to the forum. You could try php date() and strtotime() functions:

<txp:rah_function call="date" format="Y-m-d" thing="here">
    <txp:rah_function call="strtotime" time="tomorrow" />
</txp:rah_function>

In recent (4.7+?) txp versions you can also register these functions and call

<txp:evaluate query="date('Y-m-d', strtotime('tomorrow')" />

Hope that helps.

Offline

#69 2021-03-10 04:13:26

TheMakmal
New Member
From: KL-MY
Registered: 2021-03-09
Posts: 4
Website

Re: rah_function // Every PHP function is a tag

etc wrote #329184:

Hi,

welcome (back?) to the forum. You could try php date() and strtotime() functions:

<txp:rah_function call="date" format="Y-m-d" thing="here">...

In recent (4.7+?) txp versions you can also register these functions and call

<txp:evaluate query="date('Y-m-d', strtotime('tomorrow')" />...

Hope that helps.

This is perfect. Thanks!
(Yes back, thanks also for the welcoming note. Been a loyal TXP user since the mid-00s. Just can’t rmbr my u/p from the old forum. You guys make TXP the best community! :)

Offline

#70 2021-03-10 04:32:05

TheMakmal
New Member
From: KL-MY
Registered: 2021-03-09
Posts: 4
Website

Re: rah_function // Every PHP function is a tag

etc wrote #329184:

<txp:rah_function call="date" format="Y-m-d" thing="here">...

Opps, one more question. How do I change the timezone to GMT+08:00 Asia/Kuala Lumpur?
Thanks again for the help on this. Much appreciated.

Last edited by TheMakmal (2021-03-10 04:33:07)

Offline

#71 2021-03-10 06:51:59

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,090
Website GitHub Mastodon Twitter

Re: rah_function // Every PHP function is a tag

TheMakmal wrote #329187:

Opps, one more question. How do I change the timezone to GMT+08:00 Asia/Kuala Lumpur?
Thanks again for the help on this. Much appreciated.

Would setting the time zone in Admin>preferences>site solve this?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#72 2021-03-10 06:55:00

TheMakmal
New Member
From: KL-MY
Registered: 2021-03-09
Posts: 4
Website

Re: rah_function // Every PHP function is a tag

colak wrote #329188:

Would setting the time zone in Admin>preferences>site solve this?

Didn’t work. I’ve set that to my timezone. Could it be because I’m using a US based web hosting (dreamhost)?

Offline

Board footer

Powered by FluxBB