well, here's the deal.
im feeding the tweets from twitter.com using php, very nice so far, but issues start coming out.
well the feeding went fine, and i can display the tweets, etc..
i want to display these feeds using smarty..
bec. atm it just echos.. and it's placed at the top.. but i dont want that. i wanted under 'something code' in a tpl file.
this is the function..
function parse_feed($feed, $prefix, $tweet_prefix, $tweet_suffix, $suffix)
{
$feed = str_replace("<", "<", $feed);
$feed = str_replace(">", ">", $feed);
$content = explode("<content type=\"html\">", $feed);
$updated = explode("<updated>", $feed);
$amount = count($content) - 1;
for($i = 1; $i <= $amount; $i++)
{
$content_cleaner = explode("</content>", $content[$i]);
$updated_cleaner = explode("</updated>", $updated[$i]);
$tweet_date = $twitter->time_since(strtotime($updated_cleaner[0]));
echo $tweet_prefix;
echo $content_cleaner[0]." <span class='date'>".$tweet_date[1]." ".$tweet_date[0]."</span>";
echo $tweet_suffix;
}
echo $suffix;
}
and this is what displays the twets
for($i = 1; $i <= $amount; $i++)
{
$content_cleaner = explode("</content>", $content[$i]);
$updated_cleaner = explode("</updated>", $updated[$i]);
$tweet_date = $twitter->time_since(strtotime($updated_cleaner[0]));
echo $tweet_prefix;
echo $content_cleaner[0]." <span class='date'>".$tweet_date[1]." ".$tweet_date[0]."</span>";
echo $tweet_suffix;
}
i cannot seem to get it to work on smarty
Need some help
Started by abdelrahman, Dec 26 2008 10:15 AM
3 replies to this topic
#1
Posted 26 December 2008 - 10:15 AM
#2
Posted 26 December 2008 - 11:55 AM
Try to replace echo with return.
Then you can assign the result to smarty.Something like that:
Then in smarty would be:
//offtopic: If I'm wrong, try to explane with simple word, because my english is not too good.
Then you can assign the result to smarty.Something like that:
$smarty->assign('myfunction', $myfunction());
Then in smarty would be:
{$myfunction} and the code will be output the place where you want, not at the top of the page.//offtopic: If I'm wrong, try to explane with simple word, because my english is not too good.
Edited by Pr0oF, 26 December 2008 - 11:56 AM.
#3
Posted 26 December 2008 - 01:24 PM
hey, thanks for the reply.
I did as you told me,
$smarty->assign('parse_feed', $twitter->parse_feed($twitterFeed, $prefix, $tweet_prefix, $tweetsuffix, $suffix));
and when i do that, it's as if im exactly doing
$twitter->parse_feed($twitterFeed, $prefix, $tweet_prefix, $tweetsuffix, $suffix);
so, it doesn't really work
I did as you told me,
$smarty->assign('parse_feed', $twitter->parse_feed($twitterFeed, $prefix, $tweet_prefix, $tweetsuffix, $suffix));
and when i do that, it's as if im exactly doing
$twitter->parse_feed($twitterFeed, $prefix, $tweet_prefix, $tweetsuffix, $suffix);
so, it doesn't really work
#4
Posted 26 December 2008 - 02:26 PM
If i understand you correctly, then you must try like this:
this would be your document where your php scripts are located
this is your template file
This is just an example ofcourse. If there is still a problem write a pm to me.
this would be your document where your php scripts are located
function test($a, $b)
{
if(is_numeric($a) && is_numeric($b))
{
$doSomeMath = ($a * $b); // just for example :D
return $doSomeMath;
}
else
{
return false;
}
}
$first = 12;
$second = 22;
include('teconn.php'); // this is my file where i locate smarty libs e.t.c. (ignore it)
$smarty = new smarty_connect;
$smarty->assign('myfunction', test($first, $second));
$smarty->display('index.tpl');
this is your template file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
<div style="padding:5px; border:1px dashed maroon;">
{$myfunction}
</div>
</body>
</html>
This is just an example ofcourse. If there is still a problem write a pm to me.
Edited by Pr0oF, 26 December 2008 - 02:27 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
