Page 1 of 1

templates and PHP code again

Posted: Tue Feb 06, 2007 2:02 pm
by juergen
Hi,

Garvin has given a hint solving this by refering to the FAQ.
http://board.s9y.org/viewtopic.php?t=87 ... p+template

I want to try this using the "The "hackish but even easier way" at the moment. It works fine, but I have trouble assigning the value of a CustomField (TFHUser) to a PHP variable. It doesn't work, the variable is empty.

What goes wrong? Sorry for my simple question...

Juergen

<div class='serendipity_comment'>
{$entry.properties.ep_TFHUser} <--- only for test, it works

{php}
$leiter=$entry.properties.ep_TFHUser; <--- $leiter is still empty
include ('http://www.mydomain.de/foo/bar/proj.php');
{/php}
</div>

Re: templates and PHP code again

Posted: Tue Feb 06, 2007 2:35 pm
by garvinhicking
Hi!
{php}
$leiter=$entry.properties.ep_TFHUser; <--- $leiter is still empty
include ('http://www.mydomain.de/foo/bar/proj.php');
{/php}
</div>
That won't work. PHP addresses variables differently, you need to use

Code: Select all

$leiter = $entry['properties']['ep_TFHUser'];
HTH,
Garvin

Re: templates and PHP code again

Posted: Tue Feb 06, 2007 3:25 pm
by juergen
garvinhicking wrote:

Code: Select all

$leiter = $entry['properties']['ep_TFHUser'];
HTH,
Not really. $leiter is still empty. Please look at the bottom of
http://blog.juergen-luebeck.de/archives ... urity.html
for an example. 'icke' is the value of $entry.properties.ep_TFHUser
My code for testing in entries.tpl is now:

Code: Select all

<div class='serendipity_comment'>
{$entry.properties.ep_TFHUser}
</div>
<div class='serendipity_comment'>
{php}
$leiter = $entry['properties']['ep_TFHUser']; 
echo 'echo in PHP: '.$leiter;
{/php}
</div>
The config.inc.php with

Code: Select all

$serendipity['smarty']->security = false;
is located in my template dir.

Juergen

Re: templates and PHP code again

Posted: Tue Feb 06, 2007 3:44 pm
by garvinhicking
Hi!

Hm, Maybe the variable $entry is not available. Do a print_R($GLOBALS) in your PHP section and search for where you find the variable? :)

Else you might need to register a custom smarty modifier/function via config.inc.php (which is also covered in the FAQ, AFAIR).

HTH,
Garvin