Jump to content

Reusable group of fields


Jugibur
 Share

Recommended Posts

Hi everybody,

I'm currently using Contao but for complex (structural) data it's not ideal without plugins like meta models.

I like the open concept of ProcessWire and the easy editing, so play around with it and try to understand.

But I'm wondering how could I build reusable group of fields, i.e.

- Quotes (field for text and author)

- Images with styles or alignment to select for the user (field for image and dropdown for class names)

- A group of arbitrary buttons (field for title, page link, icon?, etc.)

(In Contao I'm using currently "Rocksolid Custom Elements" to build such reusable group of fields)

And besides that it would be great to set a template for each of them for markup an logic.

So i.e. the buttons template have a template with a for-loop and placing all user inputs.

I have found the fieldset, but that more for visual grouping an I can't reuse this groups for other templates.

So I'm wondering how could this be solved the best way in ProcessWire?

Thanks for your suggestions!

Juergen

Link to comment
Share on other sites

Every field is reusable in ProcessWire out of the box.

 

And besides that it would be great to set a template for each of them for markup an logic.

So i.e. the buttons template have a template with a for-loop and placing all user inputs.

This is how it works by default with processwire.

You create the fields, create templates, assign the fields and optionally give the template a file to give it a view and to write markup or logic in it.

For repeatable element we have Pagetables, Repeaters etc. All working with the above concept.

  • Like 1
Link to comment
Share on other sites

Thanks, haven't seen the repeater before but installed it now. Great!

So for repeater it is possible to build an individual template file, but sadly not for a single field (if I'm looked right).

Say you want give each textfield a surrounding div with a class I must build a function for that, where I'm wrapping the given field, right?

Additionally I have found "hooking" for manipulating a field, but it seems more complex for me instead of using a function.

Btw: I'm reading the docs bit by bit, but there is so much to understand and I'm not the best programmer :-/

Link to comment
Share on other sites

@Jugibur,

Welcome to PW and the forums. 

What the others said :-). If you are in no hurry to build something, I'd suggest stick with reading the docs first. Otherwise you might end up doing things the hard way. There really is no magic in wrapping fields with HTML. You don't need to create a function for that. It's as simple as outputting something like below in your template file.

$out = "<div class='my_field_class'>" . $page->body . "</div>";// body is a text field called 'body' on the current page
echo $out;

Please note there are different ways of outputting code within HTML...(as you will see in examples in the Docs and the forums. The above is just one way.

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

Thanks for the suggestions and the welcome!

I found the templates for pages, but my question was more in relationship of the input fields itself.

In this way you could reuse the template files of a single field in more projects. In the page template you could then use a render-method like it's possible with the repeater field.

But I think it's no big issue for me, not to have such a principle in a single field – perhaps I'm just searching for it because it's used in Contao (called "elements").

Yes, I must read and try more to get all the possibilities of ProcessWire.

Link to comment
Share on other sites

The trick is - really al content is a page in PW - page is _not_ the term like in other CMS...so generally _all_ pages are reusable groups of fields.

Repeaters and Pagetables are only a special input or better editing interface for some kind of content.

Behind the scene a Repeater or a Pagetable are using real pages....;)

welcome to Processwire be not afraid you are at home.... ^-^

  • Like 3
Link to comment
Share on other sites

  • 11 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...