Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
Re: rah_function // Every PHP function is a tag
You can try to replace strtotime
with txp own safe_strtotime
function, but I’m not sure. Timezones are always a headache.
Offline
Re: rah_function // Every PHP function is a tag
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline