Page 1 of 1

How does handlebars(HBS) interact with the database ?

Posted: Mon Sep 05, 2016 7:40 am
by gautamz07
hey guys i just started using this blogging system called postleaf and it uses a templating language called handlebars http://handlebarsjs.com/ now i was wondering how handlebars really works , because on inpecting the code i found code like below:

Code: Select all

{{#each posts}}

    <div class="sample animated fadeIn">
        <div class="container">
            <div class="title animated fadeInUp">
                <a href="{{post_url}}">
                    <h1>{{title}}</h1>
                </a>
            </div>
            {{> sidebar}}
        </div>
    </div>

    <article class="excerpt animated fadeIn {{post_class}}">
        <div class="container">
            <p>{{excerpt words="100"}}&hellip;</p>
        </div>
    </article>

{{/each}}
Now the first piece of code:

Code: Select all

{{#each posts}}
I.E. the each function is something that would be done in PHP i believe , Now a while back i used twig .

I believe that HBS(handlebars) is javascript and twing on the other hand is a PHP Engine . How do these two compare.

Also how exactly does HBS interact with the database condidering that it is JS ??? thats one of my big questions .

Re: How does handlebars(HBS) interact with the database ?

Posted: Mon Sep 05, 2016 7:46 am
by requinix
gautamz07 wrote:Now the first piece of code:

Code: Select all

{{#each posts}}
I.E. the each function is something that would be done in PHP i believe ,
...yes. Rather than a loop in PHP that outputs multiple copies of some HTML markup, the loop happens in Javascript.
gautamz07 wrote:Now a while back i used twig .

I believe that HBS(handlebars) is javascript and twing on the other hand is a PHP Engine . How do these two compare.
One is Javascript templating and the other is PHP templating. Exactly like you said.
gautamz07 wrote:Also how exactly does HBS interact with the database condidering that it is JS ??? thats one of my big questions .
It does not. Your PHP has to do that.

Re: How does handlebars(HBS) interact with the database ?

Posted: Thu Sep 08, 2016 2:48 am
by gautamz07
Thanks requinix :D