Greeting,
If i need to pass php variable to my SPIP template ( BOUCLE, FORMULAIRE ort anywhere else)
I create custom filter or dynamic tag (balise) that return variable (or even do all required manipulation with data).
Filter approach is fastest in development
-
Open or crate file squelettes/mes_fonctions.php
-
Add there you php in a such way
function filtre_php2spip() {
$variable = ‹ Hello, world! ›;
return $variable;
}
- Use it in your SPIP template
#FORMULAIRE_POST{#ANY_TAG|php2spip}
- Thats all
But IMHO the correct and right way is to create a custom dynamic tag, but due to much complicated approach,
i use customs tags only when in require a lot of operation, complicated sql queries or integration with third part modules.
If its only simple calculation - i use custom filter
Here is a tutorial about balises
https://programmer.spip.net/-Balise,64-
Hope this helps.
Best regards,
Serge
чт, 7 бер. 2019 о 12:40 Urs Riggenbach via spip-en <spip-en@rezo.net> пише:
Hello,
Than you for offering a workaround, but I find myself requiring a very
simple passing of variable from PHP to SPIP tag:
<?php
$variable = "a";
?>
#FORMULAIRE_POST{$variable}
→ Is there a way to « #SET » the variable such that I can pass it to the form?
Thanks,
Urs
On 06.02.19 09:03, JLuc wrote:
Le 05/02/2019 à 23:52, Urs Riggenbach via spip-en a écrit :
Let’s say the variable is defined in PHP:
<?php $id = function_get_id_from_database(); ?>
And I would like to replace the « 1 » below with this variable.
#FORMULAIRE_CUSTOM{1}
How would I do that? I’ve tried #EVAL with no luck.
It’s very rare when PHP is required in a SPIP squelette.
In you example’s sample code, i’d stick with « pure » SPIP
and this would answer your issue :
#SET{id,#VAL{}|function_get_id_from_database}
#FORMULAIRE_CUSTOM{#GET{id}}
My solution for now is to define in squeletes a $GLOBALS variable and
then ask for it at the formulaires/custom.php file.
Is there a more elegant solution?
For example, could you call function_get_id_from_database
directly in the formulaire’s ‹ charger › function ?
JL
spip-en@rezo.net - https://listes.rezo.net/mailman/listinfo/spip-en
–
Urs Riggenbach
Energy - Webdesign - Consulting
Weissensteinstrasse 76
4500 Solothurn
Switzerland
+41 79 918 0663 (CH)
+358 45 872 3836 (FI)
https://ursrig.com
Important: This email is confidential and may be privileged.
If you are not the intended recipient, please delete
it and notify us immediately; you should not copy
or use it for any purpose, nor disclose its contents
to any other person. Thank you.
spip-en@rezo.net - https://listes.rezo.net/mailman/listinfo/spip-en