Extension talk:PhpTags/Magic expressions

About this board

How do you pass an argument into a phptag block?

6
Woozle (talkcontribs)

The only methods I've been able to think of don't seem to work:

  • The phptag subset does not support user functions.
  • A phptag inside a template only resolves arguments after the PHP is executed (so the string processed by PHP code is "{{{1}}}" or whatever, not the argument being passed.
  • Variables defined in a phptag in one page do not persist to transcluded phptags

I feel like there must be something obvious that I'm missing, and maybe I'll think of it after I post this...

Pastakhov (talkcontribs)

> The phptag subset does not support user functions.

Yes, it does not. But you can write a template with phptag code and transclude it, it works almost similar...


> A phptag inside a template only resolves arguments after</nowiki>...

Not sure I understand you correctly. use <phptag> instead of {{#phptag:}}

to access the arguments passed to a template use $argv[1] variable, it works similar native PHP code


> Variables defined in a phptag in one page do not persist to transcluded phptags

use global variables similar native PHP code

Woozle (talkcontribs)

$argv does not ever have anything in it except the template name (in $argv[0]), according to print_r($argv).

Woozle (talkcontribs)

I think I did figure it out, 45 minutes later -- inside the template, use this:

{{#tag:phptag |
$arg1="{{{1}}}";
// code can use $arg1
}}
Pastakhov (talkcontribs)

No, it will not work as expected because it inserts {{{1}}} as php code. yes it works in some cases, but generally it is bad idea to use the code like this.

<phptag>echo $argv[1];<phptag> should print text passed as the first parameter to the template/page, for example save the code as test_phptags template and then transclude is as {{test_phptags|1=HELLO}} on a page

Woozle (talkcontribs)

Ahh, ok -- it was the "1=" part that I must have been leaving out. I will give that a try!

Reply to "How do you pass an argument into a phptag block?"

Not understandable : "This concept also allows.."

9
Wladek92 (talkcontribs)

Can you reformulate sentence "This concept also allows you to get rid of unsuitable for an expressions the wiki markup syntax in favor of any programming language." because it is not clear when being translated. Thank you.

Pastakhov (talkcontribs)

is that better?

Wladek92 (talkcontribs)

Good but i'd rather say :

This concept allows you to use a programming language for writing expressions instead of using wiki markup syntax. For example the PhpTags extension uses the syntax of PHP language

Pastakhov (talkcontribs)

you are right, thanks

Wladek92 (talkcontribs)

ok you push for translation now ? because I have not the rights. Thanks.

Pastakhov (talkcontribs)

hm, how can I push it?

Wladek92 (talkcontribs)

.. you need to be a translation administrator

Pastakhov (talkcontribs)

most likely I'm not a translation administrator

Wladek92 (talkcontribs)

ok thanks for your help; I leave the subject open waiting for an administrator action.

Reply to "Not understandable : "This concept also allows..""
There are no older topics
Return to "PhpTags/Magic expressions" page.