Jump to content

Can I Assign a PHP Syntax as a Value?


kt83

Recommended Posts

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!

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.