Jump to:

3434 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » $Even, $Odd is fine, but i need $Third...

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

Page: 1
Go to End
Author Topic: 3056 Views
  • pali
    Avatar
    Community Member
    33 Posts

    $Even, $Odd is fine, but i need $Third... Link to this post

    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

  • Mo
    Avatar
    Community Member
    504 Posts

    Re: $Even, $Odd is fine, but i need $Third... Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: $Even, $Odd is fine, but i need $Third... Link to this post

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

  • pali
    Avatar
    Community Member
    33 Posts

    Re: $Even, $Odd is fine, but i need $Third... Link to this post

    thank you for your time. this helped me.

  • biapar
    Avatar
    Forum Moderator
    435 Posts

    Re: $Even, $Odd is fine, but i need $Third... Link to this post

    Could you give us an example with Codeigniter/SS?

  • Johan
    Avatar
    Community Member
    49 Posts

    Re: $Even, $Odd is fine, but i need $Third... Link to this post

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


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

    Sorry old post but keeps popping up on Google.

    3056 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.