Re: Including variables
Joel Palmius <[email protected]> Mon, 23 Jan 2006 11:15:16 +0100 (CET)
| Newsgroups | gmane.comp.apache.mod-survey.general |
|---|---|
| Message-ID | <[email protected]> |
You need to differ between a couple of types of variables:
1. Survey variables
2. Session variables
3. Perl variables
Survey variables are only available after having been submitted. These are
accessed with {$name$}. This is used for including, for example, the name
of the respondent in subsequent pages.
Session variables can be set in perl snippets with $session->setValue().
These are accessed with {_name_}. It does not matter which type of perl
snippet they are set in, and they are available for the rest of the survey
chain. These variables can be used for controlling custom stuff.
Perl variables (ie just setting $a = 1) only live inside the perl snippet
and cannot be accessed outside it.
This is a crude example of how you can have a multi-language survey:
<SURVEY TITLE="test">
<CUSTOM ESCAPED="no"><!--
{\
$lang = $argument->ArgByName("uselanguage") || "en";
if($lang eq "en")
{
$session->setValue("namecapt","What is your name?");
$session->setValue("fruitcapt","What is your favorite fruit?");
}
if($lang eq "sw")
{
$session->setValue("namecapt","Vad heter du?");
$session->setValue("fruitcapt","Vilken är din favoritfrukt?");
}
\}
[script was included]
--></CUSTOM>
<TEXT NAME="name" CAPTION="{_namecapt_}" />
<TEXT NAME="fruit" CAPTION="{_fruitcapt_}" />
</SURVEY>
Calling this with no argument will display the survey in english. Calling
it with "?action=display&uselanguage=sw" will display it in swedish. The
CUSTOM tag can be broken out into a separate file and included with
{@..@}.
Note that in the above example you would not get any value labels in data
exports, so you might want to modify it a bit if you are going to use
CHOICE, MATRIX or LIST.
// Joel
On Mon, 23 Jan 2006, Luca Notari wrote:
> Hi,
> I need having some variables available including an external file that
> contains them.
>
> As an example, I have to do 2 surveys in 2 different languages, that are
> identical in structure; the only thing that changes is the language; As for
> the translation of mod_survey itself, the best thing (I think..) is to have
> the right variable in the right language for the CAPTION element
> (CAPTION=[variable_in_the_right_language]);
>
> I've tried {@filename@}, expecting to have all variables defined in
> [filename] available in my .survey file;
> But the only result of parsing is visible when i put in a CUSTOM TAG;
>
> I've defined a variable $myvar="text for my caption" in [filename], and
> including in my .survey file with {@filename@}, but nothing works;
>
> For example:
> {@filename@}
> <TEXT NAME="myname" CAPTION="{$myvar$}> $myvar not parsed;
> <TEXT NAME="myname" CAPTION="{$myvar}> error;
> <TEXT NAME="myname" CAPTION="{%myvar%}> $myvar not parsed;
> <TEXT NAME="myname" CAPTION="{_myvar_}> $myvar not parsed;
> <TEXT NAME="myname" CAPTION="{print $myvar }> security exception error;
>
> How can I do?
> Thanks,
>
> Luca Notari
> The Marketing Lab
> [email protected]
>
> Skickat av "Luca Notari" <[email protected]>
> till survey-discussion
>