21309 Posts in 5738 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 456 Views |
-
Display $Pos as two figures e.g.. 01, 02, 03 etc?

21 March 2012 at 3:52am
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! -
Re: Display $Pos as two figures e.g.. 01, 02, 03 etc?

21 March 2012 at 8:23am
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.
-
Re: Display $Pos as two figures e.g.. 01, 02, 03 etc?

21 March 2012 at 11:05pm Last edited: 21 March 2012 11:05pm
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)
-
Re: Display $Pos as two figures e.g.. 01, 02, 03 etc?

22 March 2012 at 10:40am
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.
-
Re: Display $Pos as two figures e.g.. 01, 02, 03 etc?

27 March 2012 at 4:51am
Sorry, almost forgot to say thanks for the help Simon!
-
Re: Display $Pos as two figures e.g.. 01, 02, 03 etc?

15 May 2012 at 9:25am
I'm having trouble getting this to work - any chance you could post your code? Thanks
| 456 Views | ||
|
Page:
1
|
Go to Top |


