passing a variable to a function from entries.tpl

Creating and modifying plugins.
Post Reply
tuntun
Regular
Posts: 5
Joined: Tue Oct 24, 2006 12:03 am

passing a variable to a function from entries.tpl

Post by tuntun »

I am kind of confused between .tpl file and passing variable to
php functions..

I want to pass the variable, entry id, to a php function
from entries.tpl ... the variable I want to pass I can print it as

how do i access it within the php code ?


I have a php fuction that I called in entries.tpl with

--------------

{$entry.id} // this is the variable I want to pass prints ok in .tpl file


{php}

// but i dunno how to access inside {php} code
echo $entry.id ; // it's not printing anyting here

$myentryid = $entry.id;

my_function($myentryid, $b);

{/php}


------------------


thanks in advance!!
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: passing a variable to a function from entries.tpl

Post by garvinhicking »

Hi!

Within the PHP section, Smarty markup does not work. PHP addresses arrays like $entry['id'], not like $entry.id. This format is just the easier smarty syntax for people that tend to cry when they see [] brackets :)

However what you're planning to do should be rethought. What do you try to do that cannot yet be done within Smarty? If it really requires PHP, it is suggested you create a config.inc.php file in your template directory, create the functions there and use the $serendipity['smarty']->register_function() Smarty API function to register your custom functions.

Then you can use {myCustomFunction} in your entries.tpl file. See more on www.s9y.org in the technical documentation.

Best regards,
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/
tuntun
Regular
Posts: 5
Joined: Tue Oct 24, 2006 12:03 am

Post by tuntun »

-- code --

{serendipity_hookPlugin hook="entries_header" addData="$entry_id"}

{foreach from=$entries item="dategroup"}
{foreach from=$dategroup.entries item="entry"}

<div class="serendipity_Entry_Date">
<div class="serendipity_Entry_Header">
{if $dategroup.is_sticky}
<h3 class="serendipity_date">{$CONST.STICKY_POSTINGS}</h3>
{else}
<h3 class="serendipity_date">{$dategroup.date|@formatTime:DATE_FORMAT_ENTRY}</h3>
{/if}

</div>

{$entry.id}

{php} echo "id is " . $entry['id']; // printing nothing right now
// my_function ($entry['id'] , 5 );
{/php}

. . .

------

there is a php function that i want to call to....
the php function is downloaded from the net...
it's probably possible to rewrite the whole thing in smarty...

just looking for an easier way...to get it done...
so I need to pass the $entry.id to the function...

is there anyway I can get $entry.id value from
within {php} {/php} ?

thanks for your help...
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Maybe you can find more on this in the Smarty documentation on smarty.php.net. Putting the function into your templates config.inc.php and using the register_function() method is definitely a way it would work, yes.
is there anyway I can get $entry.id value from
within {php} {/php} ?
If the $entry['id'] thing does not work, I know of no way. Maybe the smarty documentation on the {php} function gives more clues on that.

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