Postleaf / postleaf

Simple, beautiful publishing with Node.js.
https://www.postleaf.org/
MIT License
505 stars 203 forks source link

Passing data to templates #109

Open mtahmed opened 5 years ago

mtahmed commented 5 years ago

Is it possible to pass data to a template? There is stuff like meta.title but is it possible to pass arbitrary data to templates from the post editor? E.g. in addition to the image for a post, I would also like to pass an image description and render it under the image as an image subtitle.

claviska commented 5 years ago

Sorry, this isn't possible yet.

mtahmed commented 5 years ago

I could try to implement it if I could get some pointers/help. I was thinking something like this:

Does that sound reasonable?

claviska commented 5 years ago

The scope of this feature might be larger than we're considering.

I'm not sure it makes sense attaching custom data to the theme. That would mean switching themes destroys custom data (or at least renders it useless when you switch to other themes). Shouldn't it be attached at a higher level? Then supportive themes can use the helper API to access the data and use it however it sees fit. (I'm open to hearing use cases and alternative views here.)

They could be 3-tuples: <variable_name, short_name, description

It should probably include a type so the app can use an appropriate input or alternative (e.g. textbox, email, number, color, date, etc.). Taking it a step further (at least for the sake of discussion) it would be a good idea to add some kind of validation options as well.

Curious...how would short_name differ from variable_name?

mtahmed commented 5 years ago

Shouldn't it be attached at a higher level? Then supportive themes can use the helper API to access the data and use it however it sees fit. (I'm open to hearing use cases and alternative views here.)

Hmm you make a good point. Even if custom fields are a more high-level concept, unless all themes stick to the same set of variables, those custom fields would become irrelevant upon theme switch.

I guess the themes would get some dictionary and can lookup whatever variables are relevant to them.

Curious...how would short_name differ from variable_name?

short_name would be something like "Title Image Description" and the variable_name would be something like "title_image_desc". The first would be rendered on the UI and the second would be the internal variable name.