[Ariadne-general] country name

Auke van Slooten auke at muze.nl
Tue Feb 27 15:17:08 CET 2007


Jeroen van Gorkum wrote:

> Auke van Slooten, Thursday, February 15, 2007 3:03 PM:
> 
>>place. I personally think there is no problem in
>>making that specific
>>[/system/addressbook/countries/] directory readable
>>by public, its not like its secret information or
>>anything :)
> 
> 
> true, i'm trying the following:
> 
> * porganization::view.content.html in the root of some psite
> 
> <pinp>
> ...
>   $countryPath = '/system/addressbook/countries/' . $data->country
> . '/';
>   $geographicalAddress[] = current(get($countryPath, 'put.name',
> array('lang' => $nls)));
> ...
> [later on: html-ify $geographicalAddress[] and print it]
> </pinp>
> 
> * pobject::put.name in /system/addressbook/countries/
> 
> <pinp>
> $lang = getvar('lang');
> 
> // see if the language is defined, and the translated
> // name is not empty. otherwise return the name in
> // the default language.
> if ($data->$lang && $data->$lang->name) {
>   putvar('arResult', $data->$lang->name);
> } else {
>   putvar('arResult', $nlsdata->name);
> }
> </pinp>
> 
> i can't save the last template; ariadne complains "expected
> variable name following ($this->data->) at line 7". i tried all
> sorts of things with curly braces ($data->{$lang}->name), but
> ariadne still refuses to save the template.
> 
> why is this?

That is because its PINP, not PHP :)

Your template gets compiled to something along the following lines:

...
if ($this->data->$this->lang && $this->data->$this->lang->name) {
   putvar('arResult', $this->data->$this->lang->name);
} else {
   putvar('arResult', $this->nlsdata->name);
}
...

$this->data->$this->lang is not valid php, it should be $this->data->{$this->lang}
or something. But I'm not sure the PINP compiler is ok with that. Anyway, the solution
is the getValue method, rewrite the pinp template to something like this:

<pinp>
   $lang = getvar('lang');

   // see if the language is defined, and the translated
   // name is not empty. otherwise return the name in
   // the default language.
   $name = getValue('name', $lang);
   if ($name) {
     putvar('arResult', $name);
   } else {
     putvar('arResult', $nlsdata->name);
   }
</pinp>

There is also a setValue method, which does the same for setting values:

setValue('name', $name, $lang);

the $lang value always defaults to $nls if you enter no value.

regards,
Auke van Slooten
Muze



More information about the Ariadne-general mailing list