templates and PHP code again

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
juergen
Regular
Posts: 55
Joined: Tue Jul 04, 2006 2:23 pm
Location: Mayence, Germany
Contact:

templates and PHP code again

Post 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>
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: templates and PHP code again

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
juergen
Regular
Posts: 55
Joined: Tue Jul 04, 2006 2:23 pm
Location: Mayence, Germany
Contact:

Re: templates and PHP code again

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: templates and PHP code again

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply