TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Need some help with PHPTAL (http://www.talkphp.com/general/3612-need-some-help-phptal.html)

Tanax 11-15-2008 04:04 PM

Need some help with PHPTAL
 
Hi!

I'm wondering what's wrong with this:
HTML Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
        <head>
                <title tal:content="title">Your site name here</title>
        </head>
       
        <body>
               
                <table tal:condition="show">
           
            <caption>Images</caption>
           
            <tbody>
           
                <tr tal:repeat="image images">
                    <td tal:define="global img string:$path thumb/ $image/image_path"><img  src="${img}" /></td>
                </tr>
               
            </tbody>
           
        </table>
       
        <div tal:condition="not:show">This user has no images</div>               
               
        </body>
</html>

Gives me:
Code:

Message: Unable to find path images in current scope
I'm new to PHPTAL, so I really need help =/
Thanks in advance!

Wildhoney 11-15-2008 04:14 PM

Do you set the base path somewhere? Though my real reason for replying isn't specifically about PHPTAL as I've never used it, but just to say that whenever I see PHPTAL it always reminds me of PiHKAL because of the similarity at first glance!

Runar 11-15-2008 06:26 PM

You will have to define images somewhere in your PHP script, then send it to the template engine, like this:

PHP Code:

$template->images $some_array_with_data

If that did not work, please let us see some PHP code :).

Tanax 11-15-2008 11:24 PM

Quote:

Originally Posted by Wildhoney (Post 19632)
Do you set the base path somewhere? Though my real reason for replying isn't specifically about PHPTAL as I've never used it, but just to say that whenever I see PHPTAL it always reminds me of PiHKAL because of the similarity at first glance!

No need to set a base path with PHPTAL, but thanks!

Quote:

Originally Posted by Runar (Post 19635)
You will have to define images somewhere in your PHP script, then send it to the template engine, like this:

PHP Code:

$template->images $some_array_with_data

If that did not work, please let us see some PHP code :).

Thank you! This worked.
Problem solved :-)

Tanax 11-16-2008 12:01 AM

Okey, so a new problem occured. Not really an error, but a problem.

I got this:
HTML Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
       
        <head>
               
                <title tal:content="title">Your site name here</title>

        </head>
       
        <body>
               
                <span tal:condition="showUploadlink"><a href="upload.php">Upload an image</a></span>
               
                <br /><br />

                <table tal:condition="showImages" cellspacing="5px">
               
                        <caption>Images</caption>
                       
                        <tbody>
                       
                                <tr>
                                        <td tal:repeat="image images">
                                                <img src="${path}/${image/image_path}" />
                                        </td>
                                </tr>
                               
                        </tbody>
                       
                </table>
               
                <div tal:condition="not:showImages">This user has no images</div>
               
        </body>
       
</html>

Problem is that the td:s keep going on forever. If I put an array of images, that is 100 images, it will list 100 images on the same row. If I place the tal:repeat in the tr tag instead, it will list 100 images on 100 rows. So how can I make a repeat that makes a new tr after say.. 6 images?

So that it produces this:
Code:

<tr>
<td>img</td>
<td>img</td>
<td>img</td>
<td>img</td>
<td>img</td>
<td>img</td>
</tr>
<tr>
<td>img</td>
<td>img</td>
<td>img</td>
<td>img</td>
<td>img</td>
<td>img</td>
</tr>

etc..

Thanks in advance!

Tanax 11-18-2008 05:43 PM

Anyone?? Please I really need this, and I have no idea how to solve this =/

Tanax 11-22-2008 06:52 PM

Solved it! Thanks anyways.

Village Idiot 11-22-2008 07:26 PM

What was the issue?

Enfernikus 11-22-2008 08:41 PM

Quote:

Originally Posted by Tanax (Post 19824)
Solved it! Thanks anyways.

As Salathe has mentioned before, it'd be more useful if you took two to five minutes to outline the problem ( even that you don't really need to do since the thread has the problem in question outlined ) and the solution in a semi-detailed manner rather then replying with the above or something like it.

That being said, what was the issue?

Tanax 11-22-2008 09:12 PM

It's funny that you didn't even seem to care before, and now you want to know everything. If I wouldn't have posted that I solved it, noone could care less if I solved it, or not. But now that I did, I get 2 replies almost directly.

The issue(problem) was that I wanted to limit the number of results PER row. And if I placed the repeat in the td tag it would write alot of results on the same row. If I were instead to place the repeat in the tr tag, it would just write alot of results with only 1 result per row. I wanted to limit this so I could have for example 6 results per row.

The solution was to use array_chunk:
HTML Code:

                <table tal:condition="showImages" cellspacing="5px">
                       
                        <tbody>
                       
                                <tr tal:repeat="chunk php:array_chunk(images, 5)">
                                        <td tal:repeat="image chunk">
                                                <a href="view.php?image=${image/image_id}"><img src="${path}/${image/image_name}" border="0" /></a>
                                        </td>
                                </tr>
                               
                        </tbody>
                       
                </table>


Village Idiot 11-22-2008 10:06 PM

Quote:

Originally Posted by Tanax (Post 19837)
It's funny that you didn't even seem to care before, and now you want to know everything. If I wouldn't have posted that I solved it, noone could care less if I solved it, or not. But now that I did, I get 2 replies almost directly.

If I didn't give a shit, I would not have asked what the problem was. If I knew the issue, why on earth would I have withheld it? It is not that I didn't care, it is that I did not know the answer to your question. But now that you found it, it would be useful for everyone if you posted the solution.

Don't accuse us of not caring, if we didn't care we wouldn't be on this forum.

Enfernikus 11-22-2008 10:26 PM

If I knew the answer I would've posted, there's not much use in posting in a thread of which the original statement or question you've no knowledge of.

Tanax 11-22-2008 11:24 PM

Look at it from my point of view. I didn't get any replies(I got replies to my first question, yes. But I meant my second question). My conclusion was that noone was interested, nor cared about it. Then why should I post how I solved it, if I thought noone was interested in it?

And I meant that it didn't seem like you cared BEFORE I solved it. When I solved it, obviously I saw you were interested. But how should I know that before? I couldn't. Hence I didn't post the solution.

But now I did.

nightowl 02-06-2009 03:31 PM

if you post a question, and you find the answer yourself, it's just polite to post the answer. a lot of people are reading, but you can't expect everyone who doens't know the answer to say "i care, but i don't know the answer".

more: i just dropped in now, and I find the solution to a problem wihtout having to ask. you just shared vital information with the community, which is great !


All times are GMT. The time now is 11:25 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0