mercredi 21 mars 2018

Hogen.js - Load nested template with JS

I got a postings template (Hogen.js) were I load data (api call from Laravel 5.3) into it.
I managed to load, compile and render the template and the data correctly.

Problem:
I have jquery/vanilla js scripts that need to work with the template and the data but somehow this JS is completely ignored by the rendered template and it doesn't work (onClick, other ajax calls etc.).

My load/render JS:

  var $page = 1;
var source   = $("#postTemplate").html();
var template = Hogan.compile(source);
$.ajax({
   url: '/api/postings',
   data: { page: $page} ,
   type: 'POST',
   success: function(data) {
        var output = template.render(data);
        $('.posts-container').prepend(output);
   }
});  

My Template:

<script id="postTemplate" type="text/x-hogan-template">
        @ 
        <div class="post">
            <div class="image">
                <img src="@" alt="post image" />
            </div>

            <div class="info">
                <div class="like-count" data-like-id="@">
                    more html
                </div>
            </div>
            @include('partials.comments')
        </div>
        @
</script> 

I include a partial from laravel with my "comment" code that needs to be execuded aswell (fadeIn, ajaxacalls,submit etc.)

Is it possible, that I cann ot execute my JS with the newly rendered template or DOM, because it's not available at document.ready?

Do I need to switch my template engine? Any other way to make this work?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2HRK6C6
via IFTTT

Aucun commentaire:

Enregistrer un commentaire