Page 1 of 1
passing a variable to a function from entries.tpl
Posted: Tue Oct 24, 2006 12:13 am
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!!
Re: passing a variable to a function from entries.tpl
Posted: Tue Oct 24, 2006 10:47 am
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
Posted: Tue Oct 24, 2006 4:15 pm
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...
Posted: Tue Oct 24, 2006 6:36 pm
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