Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Parse custom fields
Hi guys,
I need a little tips.
I’m usign glz_custom_fields to add some additional informations to my articles.
If I use checkboxes the value stored are similar to
value1|value2|value3
I want to use this string to render something like this
<ul> <li class="value1">Value 1</li> <li class="value2">Value 2</li> <li class="value3">Value 3</li> </ul>
Someone can tell me how to do that?
THX
Offline
Re: Parse custom fields
wornout wrote:
value1|value2|value3
Failing any other clever options from anyone else, smd_each can do it. Just point the include
attribute at your custom field name, e.g.:
<txp:smd_each include="custom2" subset="2" delim="|" wraptag="ul">
<li class="{smd_var_value}">{smd_var_value}</li>
</txp:smd_each>
If you want to capitalise the first character of the 2nd smd_var_value, you might have to resort to using some additional technique (a jot of PHP or some clever reformatting plugin if you’re not comfortable with PHP). I guess rah_function would be able to do it if you passed it the ucfirst function name.
Last edited by Bloke (2010-02-19 10:56:53)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Parse custom fields
Bloke wrote:
I guess rah_function would be able to do it if you passed it the ucfirst function name.
<txp:rah_function call="ucfirst">{smd_var_value}</txp:rah_function>
When we at it, alternate listing method with rah_repeat:
<txp:rah_repeat value='<txp:custom_field name="some" />' delimiter="|">
<li class="<txp:rah_repeat_value />"><txp:rah_repeat_value /></li>
</txp:rah_repeat>
Last edited by Gocom (2010-02-19 11:19:08)
Offline
Re: Parse custom fields
Nice one, Gocom. Since there’s nothing fancy going on in the custom field, I’d definitely use rah_repeat instead of smd_each. It’s simpler and no doubt quicker :-) smd_each mainly helps if you want to filter the thing you are using as well.
Last edited by Bloke (2010-02-19 11:23:29)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Parse custom fields
Thanks!!!
It works great!!!
Offline
Pages: 1