Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions

$Even, $Odd is fine, but i need $Third...


Reply

6 Posts   3102 Views

Avatar
pali

29 April 2009 at 7:46pm Community Member, 33 Posts

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 class

Thanks for big help, i would like to have SS well setuped from beginning.

Regards

pali

Avatar
Mo

27 May 2009 at 9:01pm Community Member, 509 Posts

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

Avatar
Willr

27 May 2009 at 10:46pm Forum Moderator, 5511 Posts

- 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.html

n 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.

Avatar
pali

27 May 2009 at 11:12pm Community Member, 33 Posts

thank you for your time. this helped me.

Avatar
biapar

3 December 2009 at 12:23am Forum Moderator, 435 Posts

Could you give us an example with Codeigniter/SS?

Avatar
Johan

30 October 2012 at 9:52pm (Last edited: 30 October 2012 9:53pm), Community Member, 49 Posts

<% if MultipleOf(3) %> third<% end_if %>


http://doc.silverstripe.org/framework/en/reference/templates

Sorry old post but keeps popping up on Google.