Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[RFC] Import attributes into <txp:php />
Have you ever used this ugly construction to import a value into <txp:php />
?
<txp:variable name="somevar" value='<txp:tag /> or something else' />
<txp:php>
global $variable;
$somevar = $variable['somevar'];
// use $somevar somehow
</txp:php>
Wouldn’t it be better to call simply
<txp:php somevar='<txp:tag /> or something else'>
// use $somevar somehow
</txp:php>
Internally, this would just require extract($atts)
before eval()
. Any drawbacks?
Offline
Re: [RFC] Import attributes into <txp:php />
Yes yes yes!
(I mean, yes to doing it. No drawbacks as far as I can see).
Last edited by Bloke (2021-03-11 11:39:24)
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
Re: [RFC] Import attributes into <txp:php />
Oooh, related: could I run a little request by you in 4.9 onwards? Can we rename the `php` function to tpt_php and alias it during tag registration, like we do with `tpt_link`? Any ramifications you can think of?
If we do this, we can remove this horrible hack in vendors/Textpattern/Mail/Adapter/SMTPMail.php:
$this->mailer::$validator = 'phpinternal';
which is there simply to bypass the fact that we expose ‘php’ as a global function and PHPMailer looks for a function in the global scpoe of that name and executes it as a callback to validate addresses, which causes all kinds of breakage in Txp.
Definitely for 4.9, not 4.8.5, but I forgot to mention it when I did the SMTP stuff.
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
Re: [RFC] Import attributes into <txp:php />
Bloke wrote #329211:
Yes yes yes!
(I mean, yes to doing it. No drawbacks as far as I can see).
Already done, actually, just waiting for approval.
Bloke wrote #329212:
Oooh, related: could I run a little request by you in 4.9 onwards? Can we rename the `php` function to tpt_php and alias it during tag registration, like we do with `tpt_link`? Any ramifications you can think of?
Hmm, a number of plugins is using php()
to check for user rights…
Offline
Re: [RFC] Import attributes into <txp:php />
Back on topic: I presume it would not be possible to share such variables between <txp:php>
blocks? Currently, with the variable approach (ugly as it is) you can import $variable
and use it across blocks. With this proposed syntax it would only be for creating local variables, right? Kinda like JavaScript’s let
? It wouldn’t pollute the $variable
global space at all would it?
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
Re: [RFC] Import attributes into <txp:php />
etc wrote #329213:
Hmm, a number of plugins is using
php()
to check for user rights…
Yeah. Good point. Annoying. Okay, no worries. Let’s stick with the PHPMailer hack.
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
Re: [RFC] Import attributes into <txp:php />
Bloke wrote #329214:
With this proposed syntax it would only be for creating local variables, right? Kinda like JavaScript’s let? It wouldn’t pollute the $variable global space at all would it?
As I get it, yes, it would be local to php() function and not use $variable at all:
<txp:php message="hello">
echo $message;
</txp:php>
<!-- no $message defined, nor $variable['message'] ever created/altered -->
Offline
Re: [RFC] Import attributes into <txp:php />
etc wrote #329216:
As I get it, yes, it would be local to php() function and not use $variable at all:
Sweeeet, thanks.
*awaits someone to ask if we can support both local and global variables somehow using this syntax*
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
Re: [RFC] Import attributes into <txp:php />
Actually, <txp:php />
already can access its attributes/content, so nothing very much new here:
<txp:php one="1">
dmp($atts);
dmp($thing);
</txp:php>
Offline