MonkeyCMS Forum

Go Back   MonkeyCMS Forum > MonkeyCMS > Content Discussion
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2010, 02:09 PM
harvey harvey is offline
Senior Member
 
Join Date: Jun 2008
Posts: 437
Default Alternating colours

I'm using an advanced index to display just the content_longtext for every item of content in a definition, and I'd like to alternate the colour of each result for ease of reading.

I've found a very simple method for alternating table row colours here:

http://www.marvinsplaypen.com/php/table_row_colors.php

And when I create a simple php page myself I can get this to work, however I'm struggling to get it to play nicely with MonkeyCMS.

Within my page template I have this:

Code:
%% $cnt = 0; %%

(advancedindex|AdvancedIndex:MyIndex|||1)
and the advance index uses this template:

Code:
<h2 style="color:
%% addToOutput((++$cnt)%2==0) ? 'black' : 'red'; %%
;">
[content_longtext]
</h2>
but in my rendered page the h2 tags are output like so:

Code:
<h2 style="color:;">
neither red nor black is being inserted.

Any ideas what I'm doing wrong?
Reply With Quote
  #2  
Old 01-26-2010, 02:15 PM
Colin Colin is offline
Administrator
 
Join Date: Apr 2007
Posts: 1,584
Default

I'd probably not use the $cnt variable - instead, I'd pull in the content array and pop a variable into that:

Code:
%% global $arrayContent; $arrayContent['cnt'] = 0; %%

(advancedindex|AdvancedIndex:MyIndex|||1)
Code:
<h2 style="color:
%% global $arrayContent; addToOutput((++$arrayContent['cnt'])%2==0) ? 'black' : 'red'; %%
;">
[content_longtext]
</h2>
Let me know if that works
Reply With Quote
  #3  
Old 01-26-2010, 02:19 PM
harvey harvey is offline
Senior Member
 
Join Date: Jun 2008
Posts: 437
Default

Thanks for that Colin, I'm still getting the same result though?
Reply With Quote
  #4  
Old 01-26-2010, 02:21 PM
Colin Colin is offline
Administrator
 
Join Date: Apr 2007
Posts: 1,584
Default

Quote:
Originally Posted by harvey View Post
Thanks for that Colin, I'm still getting the same result though?
OK - may be that the addToContent function doesn't work with it then. I'll post an alternative in a sec
Reply With Quote
  #5  
Old 01-26-2010, 02:22 PM
harvey harvey is offline
Senior Member
 
Join Date: Jun 2008
Posts: 437
Default

Actually on inspection of the rendered code I'm getting

Code:
<h2 style="color:;">
for the first result,

Code:
<h2 style="color:1;">
for the next etc...
Reply With Quote
  #6  
Old 01-26-2010, 02:22 PM
Colin Colin is offline
Administrator
 
Join Date: Apr 2007
Posts: 1,584
Default

Try this:

Code:
<h2 style="color:
%% global $arrayContent; if ($arrayContent['cnt'] == 1) ** $arrayContent['cnt'] = 2; addToOutput('black'); ** else **  $arrayContent['cnt'] = 1; addToOutput('red'); ** %%
;">
[content_longtext]
</h2>
Replace the **'s with curly brackets.
Reply With Quote
  #7  
Old 01-26-2010, 02:24 PM
harvey harvey is offline
Senior Member
 
Join Date: Jun 2008
Posts: 437
Default

ignore me, didn't read the curly bracket thing!
Reply With Quote
  #8  
Old 01-26-2010, 02:27 PM
harvey harvey is offline
Senior Member
 
Join Date: Jun 2008
Posts: 437
Default

taa-daa! I works, thanks a million Colin.

Is it easy to explain in lay-mans terms the difference between what I was doing and your solution?
Reply With Quote
  #9  
Old 01-26-2010, 02:28 PM
Colin Colin is offline
Administrator
 
Join Date: Apr 2007
Posts: 1,584
Default

Quote:
Originally Posted by harvey View Post
taa-daa! I works, thanks a million Colin.

Is it easy to explain in lay-mans terms the difference between what I was doing and your solution?
Not really - I'm not really sure how the previous solution should have worked - obviously some short hand way.

Mine is probably a bit messier, but works
Reply With Quote
  #10  
Old 01-26-2010, 02:30 PM
harvey harvey is offline
Senior Member
 
Join Date: Jun 2008
Posts: 437
Default

Gotcha, that's great, and very useful, I can see me using this a lot!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 11:19 AM.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© Poisonous Monkey