<html>
<body>
<font size=5><b><i>Hi Peter,<br><br>
</i></b></font>Thank you. I´ve read. I´ve understand something at least.
:). I´ve followed your instructions. But, still... I can´t get it to
work. <br><br>
What I´m sure about is that in config.php I´m including my cookbook and
therefor "creating" the function there. <br><br>
The Markup works. I can call the function with my markup (:my_function:)
and if I user "return "Hello!" at the end of the function
I´m getting a "Hello!" in my broweser every time the function
is called. <br><br>
So far so good. <br><br>
The part in my function that reads a form-field also works (havent
mentioned that part before in this thread). <br><br>
These to lines reads the field (with the name
"form_field_name") and stores it in $retstr and returns it. The
text entered in the form is then displayed when the function is clled.
<br><br>
main_function()<br>
{<br>
<x-tab>        </x-tab>$retstr =
stripmagic($_REQUEST['form_field_name']);<br>
<x-tab>        </x-tab>return
$retstr;<br>
}<br><br>
Still - so far so good. <br><br>
But - now I want to use that string as a PageVariabel to be displayed on
any page in my wiki until it is changed by a call to the same function
and replaced with the new text in the form field. Just to be clear - the
text should be user uniq. I´m not trying to do anything between different
users. <br><br>
I'm now trying this;<br><br>
main_function()<br>
{<br>
<x-tab>        </x-tab>global
$FmtPV;<br><br>
<x-tab>        </x-tab>$retstr =
stripmagic($_REQUEST['form_field_name']);<br>
<x-tab>        </x-tab>
$FmtPV['$MyVariable'] = '$retstr';<br>
<x-tab>        </x-tab><br>
<x-tab>        </x-tab>return
$retstr;<br>
}<br><br>
And thereafter I try to display the PageVariabel I´ve created
with;<br><br>
{$MyVariable}<br><br>
On the wiki-pages where I want it to be displayed...<br><br>
(I´ve also tried {*MyVariable} since I somewhere read that the asterix
makes the PageVariabel more global but stil with no success.)<br><br>
But... this doesent work. :(<br><br>
Please, kick me in the right directions... :) <br><br>
Thanx in advance and regards,<br>
/ Thomas.<br><br>
<br><br>
At 2011-02-04 15:55, Peter Bowers wrote:<br>
<blockquote type=cite class=cite cite="">On Fri, Feb 4, 2011 at 9:12 AM,
Thomas Lundgren <publik@lundgren.nu> wrote:<br>
> At 2011-02-04 05:17, Peter Bowers wrote:<br>
>><br>
>> On Fri, Feb 4, 2011 at 1:04 AM, Thomas Lundgren
<publik@lundgren.nu><br>
>> wrote:<br>
>> > On a page I call a cookbook-script-function with a markup
like;<br>
>> ><br>
>> > (:my_function:)<br>
>> ><br>
>> > In the cookbook i have a function that checks the value in
a form-field<br>
>> > every time it is called and sets the result in a
PageVariable.<br>
>> ><br>
>> > I want to use that variable on any page as any other
PageVariable like;<br>
>> ><br>
>> > {$MyVariable}<br>
>> ><br>
>> > BUT. I can´t get this to work...<br>
>> ><br>
>> > I can use $FmtPV in config.php and in the cookbook-script
and set the<br>
>> > variabel $MyVariable. But I can´t change the variable
content in the<br>
>> > function that is called in the cookbook-script.<br>
>><br>
>> A couple easy things to check right off...<br>
>><br>
>> (1) Make sure you have $FmtPV declared as a global in your
function<br>
>> (2) Make sure your markup rule is ordered such that the changes
you<br>
>> are making occur before they are used (i.e., '<{$var}' or
before, use<br>
>> ?action=ruleset with diag turned on to confirm the order)<br>
><br>
> Many thanks for you quick answer - but...<br>
><br>
> (1) I´m declaring $FmtPV as a global in my cookbook-script (se
below).<br><br>
Yes, it was probably too much to hope for that we would have 2 such<br>
easy fixes inside a couple weeks... :-)  (Although see below --<br>
lightning *does* strike twice in the same place sometimes... :-) 
)<br><br>
> (2) I think I don´t understand what you are saying. :)  I don´t
user<br>
> Markup() to set the variable in any way - only to create the
function that<br>
> sets the variable.... So where and how should I use the '<{$var}'
?<br><br>
Actually, no.  You're not "creating" the function at that
point -- you<br>
are "calling" the function there.  At the point when you
have the line<br>
in your config.php:<br>
===(snip)===<br>
include_once("$FarmD/cookbook/my_cookbook.php");<br>
===(snip)===<br>
...you have "created" the function.  PHP is an interpreted
language<br>
(in most scenarios) but it does all the interpretation "up
front" at<br>
the moment of include'ing or require'ing the code.  So when
your<br>
Markup says this:<br><br>
> Markup('my_function', '_begin', 
'/\\(:my_function(.*?):\\)/e',<br>
> 'main_function("$1")');<br><br>
You are saying "look for the pattern that looks like
(:my_function<br>
<something>:) and when you find it *call* the function as if you
had<br>
code like this:<br>
===(snip)===<br>
main_function("<something>");<br>
===(snip)===<br><br>
And the '_begin' says to do that at the very beginning when you've<br>
just started processing rules.  One disadvantage of this is that
if<br>
you were to put something like this:<br>
===(snip)===<br>
[@<br>
(:my_function xyz:)<br>
@]<br>
===(snip)===<br><br>
it would be undefined as to whether your function would be run or
not.<br>
 (By standard usage it shouldn't be if enclosed with [@...@] or<br>
[=...=] or (:markup:) [=...=] (:markupend:) or etc.<br><br>
So I would change it to "<{$var}" instead of
"_begin", but I doubt<br>
that is your problem...<br><br>
Where you have a problem is in your *placement* of the line:<br><br>
===(snip)===<br>
global $FmtPV;<br>
===(snip)===<br><br>
If you want it to be global for a given function, you have to
declare<br>
it global *within that function*.<br><br>
Instead of this:<br><br>
> global $FmtPV;<br>
><br>
> function main_function( $opts )<br>
> {<br>
>        { code that set
$ToMyVariable to what it should be... }<br>
><br>
>        $FmtPV['$MyVariable'] =
'$ToMyVariable'';<br>
><br>
>        return;<br>
> }<br><br>
you should have this:<br><br>
> function main_function( $opts )<br>
> {<br>
>    global $FmtPV;<br>
>        { code that set
$ToMyVariable to what it should be... }<br>
><br>
>        $FmtPV['$MyVariable'] =
'$ToMyVariable'';<br>
><br>
>        return;<br>
> }<br><br>
I think when you fix that I think you will have good success. 
Of<br>
course, there may be other problems, but I know that's at least the<br>
first layer of the onion...<br><br>
-Peter</blockquote></body>
</html>