XaminProject / handlebars.php

Handlebars processor for php
331 stars 134 forks source link

Helper that have another helper inside that modify its behavior #157

Closed jcubic closed 7 years ago

jcubic commented 7 years ago

I want to implement for helper that will work the same as each but I want it to have pagination helper inside that will modify for behavior for instance:

{{#for foo}}
  {{this}}
{{pagination 10}}
{{/for}}

that will render 10 items from foo and and display pagination html (link previous next and numbers between). pagination should allow for custom template like:

{{#for foo}}
  {{this}}
{{#pagination 10}}
    <a href="list?page={{prev}}">{{prev}}</a>
   {{#each pages}}
      <a href="list?page={{this}}">{{this}}</a>
   {{/each}}
    <a href="list?page={{next}}">{{next}}</a>
{{/pagination}}
{{/for}}

is it possible to create helpers like for and pagination?

everplays commented 7 years ago

Exactly what's stopping you from implementing it?

jcubic commented 7 years ago

I don't know how to pass number 10 from pagination helper to for helper and count of foo from for to pagination helper.

everplays commented 7 years ago

well, php is not multithreaded so you can implement a global state to pass info between the two. Still, it is very bad idea. Why a helper that is inside another one should be passing data to its wrapper to modify its behavior? It's very odd implementation.

mAAdhaTTah commented 7 years ago

I might suggest pagination should be handled by the model responsible for the data passed to the template on render, rather than handling this in Handlebars.

everplays commented 7 years ago

Indeed. I am closing this.