Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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
andlimit
.
Thanks working great :)
Offline
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. :)
Offline
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
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.
Offline
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.
Offline
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
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
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
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
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
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