Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

complex problem with cycle

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
heohni
Smarty Regular


Joined: 20 Sep 2006
Posts: 40

PostPosted: Thu Feb 26, 2009 10:59 am    Post subject: complex problem with cycle Reply with quote

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 Smile
But I do not want it in this case Rolling Eyes

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
View user's profile Send private message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Thu Feb 26, 2009 11:48 am    Post subject: use a trick Reply with quote

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
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Feb 26, 2009 2:53 pm    Post subject: Re: complex problem with cycle Reply with quote

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 Smile
But I do not want it in this case Rolling Eyes

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP