3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2528 Views |
-
$Even, $Odd is fine, but i need $Third...

29 April 2009 at 7:46pm
Hi,
i need special css class for every third product in productgroup.
in php its easy, im just using $i%3, but what is the simplest solution in SS template file?
Anyway, im using CI more than year, i created custom CMS, but was tired from neverending development of basic modules. I think SS is great for my purposes. Thanks for great work.
I have one question, probably written somewhere in docs, but i read tons of materials last days...:
- i installed commerce module, which is stored in webroot
- i need to change some features at ecommerce/code/products/Product.php (add some more $has_many relations, add getCMSFields).
- Is it possible to not touch core files, just place some other code in "mysite/code" folder?
- In Codeigniter i just created MY_Product class extending Product class and i was able to use new/replacing functions from MY class as well as all other functions from default classThanks for big help, i would like to have SS well setuped from beginning.
Regards
pali
-
Re: $Even, $Odd is fine, but i need $Third...

27 May 2009 at 9:01pm
If you want to generate a class for every x number of elements in a list, what I usually do is use the $Pos literal in the template. For example, you can do something like:
<% control children %>
<div class="child-$Pos">
<h1>$Title</h1>
<a href="$Link">Visit Page</a>
</div><% end_control %>
The above code will create a new div for every child of the current page, and give each div a class of "child-xx". You would just have to create some styles for:
div.child-3, div.child-6,div.child-9 etc
Hope that helps,
Mo
-
Re: $Even, $Odd is fine, but i need $Third...

27 May 2009 at 10:46pm
- Is it possible to not touch core files, just place some other code in "mysite/code" folder?
Yes it is designed so usually (and hopefully) you are provided with ways to override classes by a) Subclassing, b) Using DataObjectDecorators (added statics etc) or c) Using Extensions.
http://doc.silverstripe.com/doku.php?id=dataobjectdecorator
http://api.silverstripe.com/default/Extension.htmln Codeigniter i just created MY_Product class extending Product class and i was able to use new/replacing functions from MY class as well as all other functions from default class
Yep Subclassing works the same In SS. Some times though you do not need to subclass - Decorating the object provides a nicer way of appending functions / fields to a class.
-
Re: $Even, $Odd is fine, but i need $Third...

27 May 2009 at 11:12pm
thank you for your time. this helped me.
-
Re: $Even, $Odd is fine, but i need $Third...

3 December 2009 at 12:23am
Could you give us an example with Codeigniter/SS?
-
Re: $Even, $Odd is fine, but i need $Third...

30 October 2012 at 9:52pm Last edited: 30 October 2012 9:53pm
<% if MultipleOf(3) %> third<% end_if %>
http://doc.silverstripe.org/framework/en/reference/templatesSorry old post but keeps popping up on Google.
| 2528 Views | ||
|
Page:
1
|
Go to Top |




