|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
heohni Smarty Regular
Joined: 20 Sep 2006 Posts: 40
|
Posted: Thu Feb 26, 2009 10:59 am Post subject: complex problem with cycle |
|
|
Hi,
I am having a problem with a kind of complex issue:
Code: |
<tr class="
{if $simular}simular
{elseif $smarty.session.checked_products[$value.ver_id] == $value.ver_id}
{cycle values="highlighttr1,highlighttr2"}
{else}
{cycle values="row1,row2"}
{/if}">
|
I have 2 colour results list.
For the normal state I use {cycle values="row1,row2"}.
The user has the possibility to select rows (like phpmyadmin does), when this happens I overwrite the class with highlighttr1 or highlighttr2.
My problem now:
Let's say list has 4 rows. On the first load t looks like:
<tr class="row1">
<tr class="row2">
<tr class="row1">
<tr class="row2">
<tr class="row1">
<tr class="row2">
After I selected row 4 and 5 and I load thepage again it will be:
<tr class="row1">
<tr class="row2">
<tr class="row1">
<tr class="highlighttr1">
<tr class="highlighttr2">
<tr class="row1">
Actually the cycles work fine
But I do not want it in this case
btw. it's a foreach loop.
What shall I do?
Work with index numbers?
Can I do this with foreach loops?
Any ideas?
Thanks!!! |
|
Back to top |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Thu Feb 26, 2009 11:48 am Post subject: use a trick |
|
|
Writing a lot of compiler tags gives you white spaces which might be invalid as a clean html output.
Insteady, try with a simpler modfier to pull your class name.
For example: <tr class="{$counter|class_name"} which becomes too short code and with clean output.
in modfier.class_name.php file, write a function: Code: | function smarty_modifier_class_name($counter, ...)
{
# All your business logic loop to note the class name,
# Checking it in session data, ...
# finally,
$myclassname = ..;
return($myclassname)
} |
This makes your template look clean, yet, you can have your own logic, when to use which class name for <TR>. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Feb 26, 2009 2:53 pm Post subject: Re: complex problem with cycle |
|
|
heohni wrote: | Hi,
I am having a problem with a kind of complex issue:
Code: |
<tr class="
{if $simular}simular
{elseif $smarty.session.checked_products[$value.ver_id] == $value.ver_id}
{cycle values="highlighttr1,highlighttr2"}
{else}
{cycle values="row1,row2"}
{/if}">
|
I have 2 colour results list.
For the normal state I use {cycle values="row1,row2"}.
The user has the possibility to select rows (like phpmyadmin does), when this happens I overwrite the class with highlighttr1 or highlighttr2.
My problem now:
Let's say list has 4 rows. On the first load t looks like:
<tr class="row1">
<tr class="row2">
<tr class="row1">
<tr class="row2">
<tr class="row1">
<tr class="row2">
After I selected row 4 and 5 and I load thepage again it will be:
<tr class="row1">
<tr class="row2">
<tr class="row1">
<tr class="highlighttr1">
<tr class="highlighttr2">
<tr class="row1">
Actually the cycles work fine
But I do not want it in this case
btw. it's a foreach loop.
What shall I do?
Work with index numbers?
Can I do this with foreach loops?
Any ideas?
Thanks!!! |
What are you wanting it do to? Remember, you can assign IDs to cycle value lists, and handle the output of them separately. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|