Quick question: how could I get $Pos to display on my template as two figures eg. "01, 02, 03" instead of "1, 2, 3"?
Thanks!
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.
- Page 11(current)
- 2
- Next 10 entries
You'll need to define a custom method for this. Something like:
public function PaddedPos($startIndex = 1) {
return sprintf('%02d', $this->Pos($startIndex));
}
%02d will pad an integer to two characters, if it is less than that, using zeros.
Thanks for the reply Simon, however I think this is a bit more tricky because I'm already calling a function on my page.php and it's the $Pos of that function that I need to pad out with leading zeros... and I just can't get it to work.
function ArticleCategories() {
return DataObject::get("ArticleCategory", "ParentID=16", "", "", "");
}
Is there any way of doing this on the template eg. something like $Pos.Nice ?
Or, on the template is it possible to write in the leading zero with something like <% if Pos<10 %>0<% end_if %> (this doesn't work though)
Otherwise I might just resort to hard coding it on the template eg. <% if Pos=1 %>01<% else if Pos=2 %>02... (horribly long winded code)
You'll either need to add the method to ArticleCategory or one of its parent classes (not the controller, though).
There's nothing like $Pos.Nice and you can't use inequalities in the template, just equalities.
Sorry, almost forgot to say thanks for the help Simon!
I'm having trouble getting this to work - any chance you could post your code? Thanks :)
Hello, does anyone have a solution for this? I'm struggling to get this to work.
Sorry I can't help - I couldn't figure out how to successfully add the method Simon used above to my ArticleCategory function and I had already wasted too much time on it so I resorted to just hand coding my templates with eg. <% if Pos=1 %>01<% else if Pos=2 %>02 ...etc.
- Page 11(current)
- 2
- Next 10 entries