Display custom field content as list

Creating and modifying plugins.
Post Reply
Atratus
Regular
Posts: 51
Joined: Fri Feb 09, 2007 7:41 pm

Display custom field content as list

Post 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...
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Display custom field content as list

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Atratus
Regular
Posts: 51
Joined: Fri Feb 09, 2007 7:41 pm

Post 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)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Atratus
Regular
Posts: 51
Joined: Fri Feb 09, 2007 7:41 pm

Post by Atratus »

Works perfect! Thank you very much!
Post Reply