Forum

Thread tagged as: Question, Third-party

Template Handlers?

Hey,

As far as I'm aware, template handlers are for output only, would that be correct?

What I'm trying to achieve is having a template handler to automatically generate inputs based on external data. So say I wanted x amount of text inputs, I'd want the template to automatically render that many text inputs. I thought I may be able to use a template handler, like so:

<perch:students> <perch:student id="text" type="textarea" label="Text" markdown="true" html="true" editor="simplemde" /> </perch:students>

Would it be possible to make it so that the inputs could be rendered admin side, based upon how many students there are? Or is that not possible?

If so, would there be another way to achieve this? Any advice on best practice for this?

Thanks!

Ryan Gittings

Ryan Gittings 1 points

  • 3 years ago

Looks like a custom app, couldn't you achieve this without using a template? (PHP generation on the page)

Maybe I'm missing something?

Ryan Gittings

Ryan Gittings 1 points
Registered Developer

It isn't a custom app, I want to be able to use it universally across content etc.

I don't think it's possible but wanted to just double check!

Ah sorry, I saw perch:students and assumed custom app.

Yeah as far as I'm aware template filters only apply for rendering the template content rather than on the edit page unfortunately.

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hi Ryan,

I think you can use a field type plus a template handler. The field type would be used for editing and the template handler's job would be to display the content on the frontend.

It's like the categories tags. What you put inside the tags are for frontend output only (e.g. catTitle). But you control the field in the edit form with attributes such as set="blog", max="4" and display-as="checkboxes".

<perch:categories id="categories" set="blog" max="4" label="Categories">
  <perch:category id="catTitle" type="text" />
</perch:categories>

I think the same goes for perch:related tags.


Would it be possible to make it so that the inputs could be rendered admin side, based upon how many students there are? Or is that not possible?

In a field type the function render_inputs() can output multiple fields.

It sounds possible. Worth a try.