Not logged in. · Lost password · Register
Forum: General Help and Support Syntax and Usage RSS
Create Ordered/Unordered list from variable
asingularity #1
Member since Jan 2019 · 2 posts
Group memberships: Members
Show profile · Link to this post
Subject: Create Ordered/Unordered list from variable
Hey all. I've done some searching and tried a few things, but nothing has quite done what i'm trying to do.
Background: I use Dokuwiki for pretty much everything at this point. It has basically become a one stop shop for me. I've got it set up for my dad to manage his train collection, recipes for folks, knowledgebase, landing page with iframes in tabs.... just all kinds of stuff. This questions is more centered around the recipe side of things.
My mother/mother in law, wife, and myself all use the recipe setup. I created a page template and I am using the bureaucracy plugin to do a nice form for folks to fill out when they add a recipe. The problem is what when they enter ingredients or directions for the recipe.
I have a text box in bureacracy named Ingredients

textarea "Ingredients"

In my template I have:

<WRAP half column>
===== Ingredients =====

I would like to find a way to generate an ordered/unordered list from the data in the variable @@Ingredients@@. That way, if someone copies and pastes it would treat each new line as a bullet point or number in order and I wouldn't have to keep going in to fix formatting.

Many Thanks!
schplurtz (Moderator) #2
Member since Nov 2009 · 463 posts · Location: France, Finistère
Group memberships: Global Moderators, Members
Show profile · Link to this post

It's possible with a little Q&D programming to create a fieldtype named ingredientlist that behaves exactly has a textarea but renders as a bullet list.

In DokuWiki directory, create a file name lib/plugins/bureaucracy/helper/fieldingredientlist.php with this content :
 * Class helper_plugin_bureaucracy_fieldingredientlist
 * @Author Schplurtz le Déboulonné <Schplurtz Arobe laposte • net>
 * Creates a multi-line input field that magically becomes an unordered list when rendering
class helper_plugin_bureaucracy_fieldingredientlist extends helper_plugin_bureaucracy_fieldtextarea {
    public function getReplacementValue() {
        $value = $this->getParam('value');
        return is_null($value) || $value === false ? '$2' : preg_replace('/^/m', '  * ', $value);
This adds a new fieldtype named ingredientlist

Then, In your form definition, replace textarea "Ingredients" with
ingredientlist   "Ingredients" and you're done. Next recipe will use a bullet list for ingredients.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-08-24, 02:32:32 (UTC +02:00)