PHP variables and SPIP

Hello,

Is it possible to pass PHP variables into the SPIP template parsing
engine; something like this as a basic example:

<?php $sectionId = 23; ?>

<BOUCLE_sections(RUBRIQUES){id_rubrique=<?php echo $sectionId; ?>}>
... html code ...
</BOUCLE_sections>

SPIP doesn't seem to evaluate the $sectionId variable being passed in
from PHP.

Thanks,
Ant

Hi,

Is it possible to pass PHP variables into the SPIP template parsing
engine; something like this as a basic example:

<?php $sectionId = 23; ?>

<BOUCLE_sections(RUBRIQUES){id_rubrique=<?php echo $sectionId; ?>}>
... html code ...
</BOUCLE_sections>

Unfortunately no, it's not possible.
The reason is that the SPIP code is interpreted before the PHP code.
Moreover, SPIP code is executed only once each $delai seconds, and not
each time the page is called, as is PHP code, therefore the value of a
PHP variable can can change from one call to another.

There is a contrib explaining that very well:

(... but still only in French)

There are some discussions and hacks to go over this mix of SPIP and
PHP, but the best wa to reach waht you want is to build some imbricated
SPIP loops which lead to the appropriate section and then simply apply
{id_rubrique}

kind regards
daniel

Daniel wrote:

Hi,

Is it possible to pass PHP variables into the SPIP template parsing
engine; something like this as a basic example:

<?php $sectionId = 23; ?>

<BOUCLE_sections(RUBRIQUES){id_rubrique=<?php echo $sectionId; ?>}>
... html code ...
</BOUCLE_sections>
   
Unfortunately no, it's not possible. The reason is that the SPIP code is interpreted before the PHP code.

Ok im not the right guy to answer questions that involve php but i just did a small php-spip bit the other day that worked (but can be uglyly slow) for me, so i can say that the code below should work for you :slight_smile:

<?php $sectionId = 23; <BOUCLE_sections(RUBRIQUES){tout}>
if (#ID_RUBRIQUE==$sectionId) {
... html code ...
}
</BOUCLE_sections>
?>

or course the loop goew through every rubrique that way :slight_smile: so speed can be an issue.

see ya
Chris