kt83 Posted July 30, 2009 Share Posted July 30, 2009 Hi All, I have this line in my .php file: $tpl -> AssignArray(array('my.tag' => 'Text Goes Here')); Instead of "Text Goes Here", I 'd like to use <?php recent_posts(); ?> as a value. How can I do that? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/168187-can-i-assign-a-php-syntax-as-a-value/ Share on other sites More sharing options...
wildteen88 Posted July 30, 2009 Share Posted July 30, 2009 You mean you want to call the recent_posts() function? Im guessing you should be able to do $tpl -> AssignArray(array('recent_posts' => recent_posts())); Quote Link to comment https://forums.phpfreaks.com/topic/168187-can-i-assign-a-php-syntax-as-a-value/#findComment-887030 Share on other sites More sharing options...
ignace Posted July 30, 2009 Share Posted July 30, 2009 You mean you want to call the recent_posts() function? Im guessing you should be able to do $tpl -> AssignArray(array('recent_posts' => recent_posts())); I think it's also possible by using nowdoc; Nowdoc is available as of php v5.3 Quote Link to comment https://forums.phpfreaks.com/topic/168187-can-i-assign-a-php-syntax-as-a-value/#findComment-887073 Share on other sites More sharing options...
kt83 Posted July 30, 2009 Author Share Posted July 30, 2009 You mean you want to call the recent_posts() function? Im guessing you should be able to do $tpl -> AssignArray(array('recent_posts' => recent_posts())); I got that to work, thanks. But for some reason, I can not place it specifically where I want it. On my site, I use templates so home.php pushes home.tpl. When I place the "recent posts" line of code into the php file, the output is displayed either before or after the content of the home.tpl file automatically. How do I stop it from doing that? I've tried using {} tags to call the variable in the home.tpl but that doesn't work... Quote Link to comment https://forums.phpfreaks.com/topic/168187-can-i-assign-a-php-syntax-as-a-value/#findComment-887140 Share on other sites More sharing options...
wildteen88 Posted July 31, 2009 Share Posted July 31, 2009 Post the code you using for generating your templates. Quote Link to comment https://forums.phpfreaks.com/topic/168187-can-i-assign-a-php-syntax-as-a-value/#findComment-887716 Share on other sites More sharing options...
kt83 Posted July 31, 2009 Author Share Posted July 31, 2009 This is what my home.php file looks like: <?php $tpl = new template; $tpl -> Load("!theme/{$GLOBALS["THEME"]}/templates/home.tpl"); $tpl -> GetObjects(); require_once("home/www/sitename/blog/wp-config.php"); $recentPosts = recent_posts(); $recentComments = get_recent_comments(); $tpl -> AssignArray(array('recent.posts' => '$recentPosts')); $tpl -> AssignArray(array('recent.comments' => '$recentComments')) $tpl-> CleanZones(); $tpl -> Flush(); ?> And inside my home.tpl file, I have, in two different divs, {recent.posts} and {recent.comments} On the page, the recent_posts and recent_comments appear before all the content and in the div where I placed {recent.posts}, appears $recentPosts and {recent.comments} appears $recentComments. I tried it without the ' ' around $recentPosts and $recentComments, but nothing came out. Hope you can figure this out. Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/168187-can-i-assign-a-php-syntax-as-a-value/#findComment-887957 Share on other sites More sharing options...
ignace Posted August 1, 2009 Share Posted August 1, 2009 $tpl -> AssignArray(array('recent.posts' => $recentPosts)); $tpl -> AssignArray(array('recent.comments' => $recentComments)); Quote Link to comment https://forums.phpfreaks.com/topic/168187-can-i-assign-a-php-syntax-as-a-value/#findComment-888197 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.