phpprocesswire

Processwire: How to store Tags as Array


I'm very new to Processwire.

I want to create a fieldtype where I can define multiple tags (all possible, not predefined ones).

I want to use them in my template as an simple array:

$tags = $page->get('tags');
// $tags = array('bananas', 'apples', 'oranges')

Because I'm creating a simple template which outputs my data as JSON for other apps. Somekind of a headless CMS.

How can i solve this? I did't found any processwire module or solution in other forums.


Solution

  • There are multiple way's to get this done. The easiest way obviously is to use a normal textfield and comma separate them. For your output you can just use

    $tags = explode(',',$page->get('tags'));
    

    If you want to have a nicer interface for inputting tags (output stays the same as above) you can use: http://modules.processwire.com/modules/textbox-list/

    For more advanced solutions like using the "page" fieldtype and in addition "InputfieldChosenSelect" have a look here: https://processwire.com/talk/topic/2010-fieldtype-for-storing-tags/

    Btw.: For Processwire the PW developer forum is always the best place to ask that kind of questions :)