![]() |
|
|
#1
|
|||
|
|||
|
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) Code:
<h2 style="color: %% addToOutput((++$cnt)%2==0) ? 'black' : 'red'; %% ;"> [content_longtext] </h2> Code:
<h2 style="color:;"> Any ideas what I'm doing wrong? |
|
#2
|
|||
|
|||
|
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> ![]() |
|
#3
|
|||
|
|||
|
Thanks for that Colin, I'm still getting the same result though?
|
|
#4
|
|||
|
|||
|
OK - may be that the addToContent function doesn't work with it then. I'll post an alternative in a sec
![]() |
|
#5
|
|||
|
|||
|
Actually on inspection of the rendered code I'm getting
Code:
<h2 style="color:;"> Code:
<h2 style="color:1;"> |
|
#6
|
|||
|
|||
|
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>
|
|
#7
|
|||
|
|||
|
ignore me, didn't read the curly bracket thing!
|
|
#8
|
|||
|
|||
|
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? |
|
#9
|
|||
|
|||
|
Quote:
Mine is probably a bit messier, but works ![]() |
|
#10
|
|||
|
|||
|
Gotcha, that's great, and very useful, I can see me using this a lot!
![]() |
![]() |
| Thread Tools | |
| Display Modes | |
|
|