Login | Forgot password | Register

X

What is OpenID?

OpenID is an Internet-wide identity system that allows you to sign in to many websites with a single account.

With OpenID, your ID becomes a URL (e.g. http://username.myopenid.com/). You can get a free OpenID for example from myopenid.com.

For more information visit the official OpenID site.

Jump to:

17480 Posts in 4474 Topics by 1973 members

Archive

SilverStripe Forums » Archive » Little Help with if statements

Our old forums are still available as a read-only archive.

Page: 1
Go to End
Author Topic: Little Help with if statements 545 Views
  • 3N1GM4
    avatar
    Community Member
    29 posts

    Little Help with if statements Link to this post

    Hello All!

    Im trying to do something like this

    <% if TotalItems - Pos = 6 %>
    ... do this code ...
    <% end_if %>

    but keep getting an error. is there a way to do PHP style if statements in a template?

    as in <= , >= , % , ect.

  • Double-A-Ron
    avatar
    Community Member
    308 posts

    Re: Little Help with if statements Link to this post

    What you should do is in the Page_Controller class for that page type, create a new function that does the calculation and returns a boolean to your template. Something like:

    function FunctionName() {
    if($this->TotalItems - $this->Pos == 6) {
    return true;
    } else {
    return false;
    }
    }

    Note, I am unsure what TotalItems and Pos actually are, but I am assuming they are part of the page object if you are referencing them in the template.

    So, then, in your template:

    <% if FunctionName %>
    ... do this code ...
    <% end_if %>

    The idea is to remove such logic from your template and always handle it in your controller.

    Cheers
    Aaron

  • 3N1GM4
    avatar
    Community Member
    29 posts

    Re: Little Help with if statements Link to this post

    Ahh well that makes sense! Thanks for the heads up!!

  • Double-A-Ron
    avatar
    Community Member
    308 posts

    Re: Little Help with if statements Link to this post

    Oh and to answer your question, no, you can't use PHP in a template. This forces you to use the MVC model the way you should.

    Cheers
    Aaron

    545 Views
Page: 1
Go to Top

Currently Online: There is nobody online.

Welcome to our latest member: AlfonsoGrondo

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

Comments on this website? Please give feedback.