3214 Posts in 848 Topics by 810 members
| Go to End | Next > | |
| Author | Topic: | 6292 Views |
-
Re: Problem with <%if > control

8 June 2010 at 5:03am
Hi!
No need to be sorry! I didn’t mean to seem angry. I’m not a native Englishman.
Some elements to remember for happy silverstriping: SS templates are not PHP, typos in the manual of an open-source project can be corrected by the users (as I just did) and there are far more lazy forum members than stupid forum questions, so keep researching and asking and you should get a lot of help here!
Regards,
Juan -
Re: Problem with <%if > control

8 June 2010 at 9:09am
Yes, I don't think this was meant as an impatient response. I was simply saying thanks as I hadnt linked through to the Docs which would have saved me time re-typing them.
Hopefully you will find the SS community very helpful.
-
Re: Problem with <%if > control

10 June 2010 at 6:54am
Thanks for the help. Thought it would be obvious. It take your point about the usage. I thought the same too. It will do for now while I learn. A better way will come to me I am sure!
-
Re: Problem with <%if > control

18 June 2010 at 5:02am Last edited: 18 June 2010 5:18am
Guys, how I can realise?
<% if $Pos%7 != 0 %>
bla-bla
<% end_if %> -
Re: Problem with <%if > control

18 June 2010 at 8:05am Last edited: 18 June 2010 8:06am
The <% if %> control structures with Silverstripe are somewhat limited. Some don't like it - I think it is great. It keeps the presentation code as clean and abstracted from the logic. Your .ss templates are much cleaner (all be it for a mild inconvenience).
So if you can't solve your task with the simple Silverstripe Template logic there is a work around...and it is a perfect solution that I have seen mentioned of the forums a few times.
Basically what you need to do is create a method in your Page class file. (the .php file in the mysite directory/code directory)
1. Create the method in your Page's Controller class:
function checkSomething(){
if (compareThis != compareThat) {
return false;
} else {
return true;
}
}2. Now that you created the method 'checkSomething' in your class file (example like Page.php). Go back to your .ss template file and you can add something like.
<% if checkSomething %>
<p>Hello World</p>
<% end_if %>Just with that simple strtucture you can build out whatever you may need as complex as you like it within the Class file. When I first saw this it opened up a whole new world within Silverstripe.
-
Re: Problem with <%if > control

18 June 2010 at 9:08am
thx, i just thought about something more clearer =)
-
Re: Problem with <%if > control

18 June 2010 at 6:37pm
In 2.4 it brings the ability to use Mod in the templates. It has got 2 new methods MultipleOf($value) and Modulus($value, $offset) which I think you're trying to do Tonyair. So in your example you can do
<% if MultipleOf(7) %>
// do stuff
<% end_if %> -
Re: Problem with <%if > control

18 June 2010 at 6:43pm Last edited: 18 June 2010 6:46pm
Hi Willr, thanks for the heads up. Are these documented somewhere?
- Ed
Edit: Just found a mention here in the new api docs...
http://api.silverstripe.org/2.4/sapphire/view/ViewableData.html
| 6292 Views | ||
| Go to Top | Next > |




