Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-07-02 06:41:45

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,615
GitHub Twitter

Registered PHP functions for the evaluate tag [Solved]

I’m sorry, but I forgot how to use a registered PHP number_format() function with a <txp:evaluate /> tag. Second: can we add multiple PHP functions (maybe within a comma separated list) ?

Last edited by Pat64 (2023-07-02 16:25:41)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#2 2023-07-02 10:06:16

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

Re: Registered PHP functions for the evaluate tag [Solved]

You first need to switch on “Advanced Options” in the Admin Settings. Then reload the page and add the PHP functions you want to use to the field PHP functions enabled in txp:evaluate. You can add several functions separated by commas just as you suggest.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2023-07-02 13:14:53

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,615
GitHub Twitter

Re: Registered PHP functions for the evaluate tag [Solved]

Thanks. Could you give me a sample with usage into a <txp:evaluate /> tag (based on the PHP number_format() function)?


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#4 2023-07-02 15:05:56

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

Re: Registered PHP functions for the evaluate tag [Solved]

I’m sorry. I realised I misunderstood your question (I did think you’d be familiar with what I wrote).

To answer your question, like this:

<txp:variable name="myval">123453465</txp:variable>
<txp:evaluate query='number_format(<txp:variable name="myval" />, 2, ",", " ")' />

<!-- returns "123 453 465,00" -->

<txp:variable name="decval">12345.3465</txp:variable>
<txp:evaluate query='number_format(<txp:variable name="decval" />, 2, ",", " ")' />

<!-- returns "12 345,35" -->

Now I also know what you mean with the comma separated php functions. I’m not sure about that.


TXP Builders – finely-crafted code, design and txp

Offline

#5 2023-07-02 16:25:19

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,615
GitHub Twitter

Re: Registered PHP functions for the evaluate tag [Solved]

Perfect !

And I found where I had a problem.

I tried (before asking some help) this:

<txp:evaluate query='number_format(custom_field(array('name'=>'pageviews')), 0, '', ' ')' />

First, the problem was caused by the use of quotation marks…

Second, I registered the PHP function as… a function like this number_format()

For all: do not add any brackets with the registered PHP functions.


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

Board footer

Powered by FluxBB