ernest
August 9, 2021, 1:46pm
1
Hello
I would like to render a numbered list of pages, but with roman numbers.
To get the numbers, I put
<?= $page->children()->listed()->num() ?>
and I get
1, 2, 3, 4…
is there a simple way to convert the numbers into roman numbers, like
I, II, III, IV… ?
Thank you!
You can convert easily via CSS: list-style-type: upper-roman
You probably mean nums()
not num()
? But that only gives you an array of numbers, not a list. What exactly do you want to achieve here?
What @ahmetbora suggested, only works for an ordered list (<ol>
), so you would have to loop through your pages collection and generate such a list.
ernest
August 9, 2021, 2:14pm
4
I made a link list like this:
<ul>
<?php foreach($page->children()->listed() as $child) : ?>
<li>
<a href= "<?= $child->url() ?>">
<span class="number"><?= $child->num() ?></span>
<?= $child->title() ?>
</a>
</li>
<?php endforeach ?>
</ul>
and I want a link list that looks like
I Link 1
II Link 2
III Link 3
IV Link 4
The CSS trick of @ahmetbora sadly didn’t work.
As @pixelijn mention, you should use <ol>
instead of <ul>
, should be work.
And then also remove this manual number
ernest
August 9, 2021, 3:00pm
7
OK I put an <ol>
tag instead of an <ul>
and I got my roman numbers.
But there is still that ugly period after the number. Is there a way to get rid of that?
And since the numbers are outside of the list, they’re not part of the link anymore. The only way to avoid that is to wrap the <a>
tag around the <li>
object.
That would result in invalid HTML, though. See “Permitted content” on this page: <ol>: The Ordered List element - HTML: HyperText Markup Language | MDN
If you absolutely must have the number inside your link (why?), then back to your original idea with the span and use a function like this to convert:
Also maybe you can use unicode characters as standalone:
Roman numerals for those who prefer non-positional notation. Everyone knows how to write in Roman 4 (Ⅳ) or 10 (Ⅹ). But what about 100, or 5000 or 100000? Just like this: Ⅽ, ↁ, ↈ.
ernest
August 10, 2021, 8:06pm
10
Thanks for your help, the script did the job!