Page 1 of 1

Display custom field content as list

Posted: Sat Aug 30, 2008 4:02 pm
by Atratus
Hey guys,

I wonder if it's possible to get the content of an custom field as a list?
I would like to insert something like this:

Code: Select all

Point One
Point Two
Point Three
But in the theme it should be automatically displayed as a list like:

Code: Select all

[ul]
[li]Point One[/li]
[li]Point Two[/li]
[li]Point Three[/li]
[/ul]
At the moment it is displayed as

Code: Select all

Point One Point Two Point Three
so in one line,without any break.

If this is possible, could anybody tell me how to do it?
Would be nice :)

And sorry for my bad english, hope you could understand what I mean...

Re: Display custom field content as list

Posted: Sat Aug 30, 2008 4:43 pm
by garvinhicking
Hi!

Simply prefix an <li>...</li> before the output of your custom fields in the entries.tpl template...like:

Code: Select all

<ol>
<li>{$entry.properties.ep_field1}</li>
<li>{$entry.properties.ep_field2}</li>
<li>{$entry.properties.ep_field3}</li>
</ol>
Regards,
Garvin

Posted: Sat Aug 30, 2008 5:02 pm
by Atratus
Ich antworte mal auf das deutsch, das ist leichter ^^°

Es geht um den Inhalt eines einzigen custom field.
In dieses Feld werden die Punkte untereinander eingegeben und ich möchte sie dann automatisch als Liste dargestellt haben. Also pro Zeile im Feld ein Listenpunkt.

Hoffe, hab mich jetzt besser ausgedrückt (und dass es ok ist, wenn ich in deutsch schreibe)

Posted: Sat Aug 30, 2008 9:25 pm
by garvinhicking
Hi!

You can write a custom PHP function. Put this into your config.inc.php of your template:

Code: Select all

<?php
function make_list($params, &$smarty) {
 $items = explode("\n", $params['value']);
 foreach($items AS $item) {
    echo '<li>' . trim($item) . '</li>';
 }
}
$serendipity['smarty']->register_function('make_list', 'make_list');
?>
and then you use this at the place of your entries.tpl:

Code: Select all

{if $entry.properties.ep_list}
<ol>
{make_list value=$entry.properties.ep_list}
</ol>
{/if}
Of course you need to replace "ep_list" with the actual custom field name you set up.

Best regards,
Garvin

Posted: Sun Aug 31, 2008 6:37 pm
by Atratus
Works perfect! Thank you very much!