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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

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


Go to End


6 Posts   5412 Views

Avatar
pali

Community Member, 33 Posts

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 class

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

Regards

pali

Avatar
Mo

Community Member, 541 Posts

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

Avatar
Willr

Forum Moderator, 5523 Posts

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

Community Member, 33 Posts

27 May 2009 at 11:12pm

thank you for your time. this helped me.

Avatar
biapar

Forum Moderator, 435 Posts

3 December 2009 at 12:23am

Could you give us an example with Codeigniter/SS?

Avatar
Johan

Community Member, 49 Posts

30 October 2012 at 9:52pm

Edited: 30/10/2012 9:53pm

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

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

Sorry old post but keeps popping up on Google.