Welcome Guest, Not a member yet? Register   Sign In
Template Parser: Parsing PHP code
#1

[eluser]Unknown[/eluser]
Hi all, this is my first time using CodeIgniter, and I've run into some problems with the parser that I can't seem to find anywhere else.

This is my current code for a view file that is to be parsed:

Code:
{paging}
<table border="1" width="200">
    <tbody>
        {posts}
        &lt;?php
        $poster_profile = $this->facebook->api("/{poster_id}");
        ?&gt;
            <tr>
                <td>
                <h3>{heading}</h3>
                {remarks}<br />
                <h4>Created by: &lt;?php echo $poster_profile['name']; ?&gt;</h4>
                <img src="http://graph.facebook.com/{poster_id}/picture" />
                {date_created}
                </td>
            </tr>
        {/posts}
    </tbody>
</table>

I've passed in an array that contains the {paging} variable, and a {posts} array that contains records from my database.

However, it would appear that the PHP code (the one with the Facebook API) gets run before the parser could parse the value inside, hence leading to errors.

Does anyone have any possible suggestions to this problem? As I need to loop through the array of posts, it's rather difficult to extract out the poster_id variable..

Thanks!

EDIT: I managed to get a workaround by doing a foreach and inserting the appropriate variables I need from Facebook beforehand into the elements of the 'posts' array. So problem solved I think. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB