[PHPTAL] tal:condition question
Hi, I have a list in my application where the first column should be one icon if the id of the offer is in an array or another icon otherwise. The array that have some icons looks something like this: $tmp[id] = 1 or 0. If id is 1, I should have one icon and another if 0. I added the array to template like this: $template-tmp = $tmp; and then I tried to do this: td tal:condition=tmp/${offers/idiffer}/td Where offers/idoffer is the list that is repeated in the table, so each row have one idoffer. Do anyone have any suggestion how I can fix this? Hope you understand my problem. Cheers, Teis ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
[PHPTAL] Tal:condition question
Hi, I am sitting with a page where I have a menu where the design is defined as a macro. In this menu, I want to have one of the elements that is Login or Logout depends on the user is logged in or logged out. So I was thinking that tal:condition could do this for me. I have a function that I can check if is true or false (true if you are logged in), but don't get it right when I should use it with the tal:condition. lia. href=. tal:condition=.?...Login/a My function that I usually check is $l-IsLoggedIn() that is accesable from all the webpage. Do someone have an idea how I can do this as best as possible? Hope for an answer. Teis ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
SV: [PHPTAL] Tal:condition question
Hi, Thanks for your quick answer. Teis Fra: phptal-boun...@lists.motion-twin.com [mailto:phptal-boun...@lists.motion-twin.com] På vegne av Marco Pivetta Sendt: 13. juli 2011 09:25 Til: Template Attribute Language for PHP Emne: Re: [PHPTAL] Tal:condition question Supposing that you've set variable l in your template, you can just write li a href=... tal:condition=l/isLoggedIn()Logout/a a href=... tal:condition=not:l/isLoggedIn()Login/a /li That will do :) Marco Pivetta http://twitter.com/Ocramius http://marco-pivetta.com On 13 July 2011 09:21, Teis Lindemark m...@teilin.net wrote: Hi, I am sitting with a page where I have a menu where the design is defined as a macro. In this menu, I want to have one of the elements that is Login or Logout depends on the user is logged in or logged out. So I was thinking that tal:condition could do this for me. I have a function that I can check if is true or false (true if you are logged in), but dont get it right when I should use it with the tal:condition. lia href= tal:condition= ?...Login/a My function that I usually check is $l-IsLoggedIn() that is accesable from all the webpage. Do someone have an idea how I can do this as best as possible? Hope for an answer. Teis ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
[PHPTAL] tal:attributes and checkboxes
Hi, The website I am working on now has a list where the user should click on a checkbox and then have then could check the items the user want and this should be used later. When I started doing this, I created the the checkbox like this: input type=checkbox name=favorite value=${offers/idoffer} OnCheckedChanged=submit(); onclick=if(this.checked) this.form.submit();/ Then I was thinking that I should place this in a array that I so place in a session variable, so when the page here refresh, the item is still checked and I also have access to the favorites later in the process. This is the code in the php file that create the array and that I place in the session vaiable: isset($_SESSION['fav']) ? $_SESSION['fav'] : $_SESSION['fav'] = null; if(isset($_GET['submit']) $_GET['submit'] == 'fav') { if(count($_SESSION['fav']) 5) { $_SESSION['fav'][] = array(idoffer = $_POST['favorite'], checked = true); } $tmp = Array(); foreach($_SESSION['fav'] as $f) { $tmp[$f['idoffer']][] = $f['checked']; } $_SESSION['fav'] = $tmp; unset($tmp); } Now I was thinking to use tal:attributes=checked x something like that to be sure that it the item is checked after the checking submit the form. Is this totally wrong way to get my idea to work? Hope anyone can help me with this one. Teis ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
[PHPTAL] Table with two array problem
Hi, I am new to use PHPTal and so far, I like it. It's great to separate php code and the xhtml code. One of my list need some data from two arrays. I have one array array1 that I use tal:repeat=offers jobOffers and find the content like this: tal:content=offers/name for example. One of the columns in the table have the data in another array, with two columns idoffer and name. The first array also have idoffer (offers/idoffer). But what I need here is that otherarray/name is placed in the row where offers/idoffer and otherarray/idoffer is equal. I can't figure this out and have been stuck here for a while. Hope someone can help me with this one. Teis ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
SV: [PHPTAL] Table with two array problem
Okey, thanks for the quick answer. But my otherArray is at format Array([0] = Array([idoffer] = INTEGER [name] = STRING) [1] ... I think the reason is that one idoffer can have more than one name, but is there an easy way to format that array correct or get this work on this array? Thanks for the answer so far ;) Teis -Opprinnelig melding- Fra: phptal-boun...@lists.motion-twin.com [mailto:phptal-boun...@lists.motion-twin.com] På vegne av Robert Goldsmith Sendt: 28. juni 2011 17:06 Til: Template Attribute Language for PHP Emne: Re: [PHPTAL] Table with two array problem I think I understand what you are saying. The easiest way to do this would be if 'idoffer' is the key for the second array (so you have an array of key/value pairs with the idoffer as the key and name as the value). Then you can effectively ask 'give me the value for this key I am giving you or, if the key doesn't exist then please give me a default value'. Imagine the following: $jobOffers = array( array('idOffer' = 'a', 'name' = 'AAA'), array('idOffer' = 'b', 'name' = 'BBB'), ); $otherArray = array( 'a' = array('name' = 'AaAa'), 'c' = array('name' = 'CcCc'), ); table tr tal:repeat=offers jobOffers td tal:content=offers/name' / td tal:content=otherArray/${offers/idOffer}/name | string:no match; / /tr /table The important part here is the ${offers/idOffer} part which is replaced by PHPTal *before* it then tries to access the value from otherArray. For the first loop through, offers/idOffer is equal to 'a' so PHPTal tries to access otherArray/a/name which succeeds while on the second loop through it tries otherArray/b/name which doesn't exist so PHPTal moves on to the next option in the value chain (using the | character) and instead picks up the string 'no match'. I hope this is what you were trying to do :) If you need something more like 'in_array' where you need to hunt through the values in otherArray to find a match you will need to write a Tale but I'd also question the efficiency of doing that and would suggest trying to use array keys where possible :) Robert On 28 Jun 2011, at 15:38, Teis Lindemark wrote: Hi, I am new to use PHPTal and so far, I like it. Its great to separate php code and the xhtml code. One of my list need some data from two arrays. I have one array array1 that I use tal:repeat=offers jobOffers and find the content like this: tal:content=offers/name for example. One of the columns in the table have the data in another array, with two columns idoffer and name. The first array also have idoffer (offers/idoffer). But what I need here is that otherarray/name is placed in the row where offers/idoffer and otherarray/idoffer is equal. I cant figure this out and have been stuck here for a while. Hope someone can help me with this one. Teis ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal
SV: SV: [PHPTAL] Table with two array problem
Thanks a lot! This works and I also learned a bit more about how PHPTAL works. Teis -Opprinnelig melding- Fra: phptal-boun...@lists.motion-twin.com [mailto:phptal-boun...@lists.motion-twin.com] På vegne av Piotr Kroczynski Sendt: 28. juni 2011 18:01 Til: Template Attribute Language for PHP Emne: Re: SV: [PHPTAL] Table with two array problem Ok maby I didn't understand you correctly. Case where there could be more than one name for idoffer: $tmpArray = array(); foreach($otherArray as $a){ $tmpArray[$a['idoffer']][] = $a['name']; } $otherArray = $tmpArray(); unset($tmpArray); then: tr tal:repeat=offers jobOffers td tal:content=offers/name/td td ul li tal:repeat=n otherArray/${offers/idoffer} tal:content=n/li /ul /td /tr Pozdrawiam Piotr Kroczyński W dniu 28.06.2011 17:41, Teis Lindemark pisze: Okey, thanks for the quick answer. But my otherArray is at format Array([0] = Array([idoffer] = INTEGER [name] = STRING) [1] ... I think the reason is that one idoffer can have more than one name, but is there an easy way to format that array correct or get this work on this array? Thanks for the answer so far ;) Teis -Opprinnelig melding- Fra: phptal-boun...@lists.motion-twin.com [mailto:phptal-boun...@lists.motion-twin.com] På vegne av Robert Goldsmith Sendt: 28. juni 2011 17:06 Til: Template Attribute Language for PHP Emne: Re: [PHPTAL] Table with two array problem I think I understand what you are saying. The easiest way to do this would be if 'idoffer' is the key for the second array (so you have an array of key/value pairs with the idoffer as the key and name as the value). Then you can effectively ask 'give me the value for this key I am giving you or, if the key doesn't exist then please give me a default value'. Imagine the following: $jobOffers = array( array('idOffer' = 'a', 'name' = 'AAA'), array('idOffer' = 'b', 'name' = 'BBB'), ); $otherArray = array( 'a' = array('name' = 'AaAa'), 'c' = array('name' = 'CcCc'), ); table tr tal:repeat=offers jobOffers td tal:content=offers/name' / td tal:content=otherArray/${offers/idOffer}/name | string:no match; / /tr /table The important part here is the ${offers/idOffer} part which is replaced by PHPTal *before* it then tries to access the value from otherArray. For the first loop through, offers/idOffer is equal to 'a' so PHPTal tries to access otherArray/a/name which succeeds while on the second loop through it tries otherArray/b/name which doesn't exist so PHPTal moves on to the next option in the value chain (using the | character) and instead picks up the string 'no match'. I hope this is what you were trying to do :) If you need something more like 'in_array' where you need to hunt through the values in otherArray to find a match you will need to write a Tale but I'd also question the efficiency of doing that and would suggest trying to use array keys where possible :) Robert On 28 Jun 2011, at 15:38, Teis Lindemark wrote: Hi, I am new to use PHPTal and so far, I like it. It’s great to separate php code and the xhtml code. One of my list need some data from two arrays. I have one array array1 that I use tal:repeat=”offers jobOffers” and find the content like this: tal:content=”offers/name” for example. One of the columns in the table have the data in another array, with two columns idoffer and name. The first array also have idoffer (offers/idoffer). But what I need here is that otherarray/name is placed in the row where offers/idoffer and otherarray/idoffer is equal. I can’t figure this out and have been stuck here for a while. Hope someone can help me with this one. Teis ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal ___ PHPTAL mailing list PHPTAL@lists.motion-twin.com http://lists.motion-twin.com/mailman/listinfo/phptal