Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this client side? #12

Open
Swanty opened this issue Aug 9, 2016 · 7 comments
Open

How to use this client side? #12

Swanty opened this issue Aug 9, 2016 · 7 comments

Comments

@Swanty
Copy link

Swanty commented Aug 9, 2016

I'm using laravel 5.2 and raw output doesn't work for me

File: resources/views/test/sample.hbs

<div class="entry">
    <h1>{{title}}</h1>
    <div class="body">{{body}}</div>
</div>

File: resources/views/template/default.blade.php

<head>
...
    <script id="sample-template" type="text/x-handlebars-template">
        @raw('test.sample')
    </script>
...
</head>

Output:

    <script id="sample-template" type="text/x-handlebars-template">
        <div class="entry">
    <h1></h1>
    <div class="body"></div>
</div>
    </script>

Basically {{title}} and {{body}} is gone, so I can't use the template in javascript.
I'm using the default config file and laravel-handlebars version 1.1.0

@Swanty
Copy link
Author

Swanty commented Aug 17, 2016

Decided to just compile the templates instead of injecting them into html.

First I tried to use laravel-elixir-handlebars from npm, but that one adds require() in compiled templates.js file, which doesn't fit my needs, also last update was a year ago and has PR's that the owner hasn't bothered to look at.

Soo I made one that works for me. If anyone is interested then you can check out at https://github.com/Swanty/laravel-elixir-handlebars

@Swanty Swanty closed this as completed Aug 17, 2016
@pdbreen
Copy link

pdbreen commented Oct 26, 2016

I also had a bit of an issue using - or more likely, understanding - raw. I expected the template to be pulled as is with minimal processing, but when tracing the code I saw it was still being compiled, but in raw mode (though I'm not sure exactly how that differs or how it would be used). In the end, since I didn't have any dependencies on blade, lang, etc in my template, I ended up using a direct php include:

<script id="product-list-template" type="text/x-handlebars-template">
<?php include(base_path('resources/views/product/hogan/product-list-template.hbs')); ?>
</script>

@Lorti
Copy link
Collaborator

Lorti commented Oct 27, 2016

You seem to be correct, raw output is currently broken. I'd be happy to review pull requests, because It may take some time until I'll get around to fix it.

We are using webpack in our pipeline, which is taking care of shipping templates to the front-end, which is why I may not have noticed this problem before.

Also, maybe @markusjwetzel can take a look into it?

@markusjwetzel
Copy link
Contributor

markusjwetzel commented Oct 31, 2016

Sorry, don't have time to look into this issue, so help is wanted. I added a hint to the raw output section of the readme file, so hopefully someone will read it in the readme or here and is able to help. :)

@greut
Copy link
Collaborator

greut commented Feb 8, 2017

This is how I do it, using basic webpack configuration: https://medium.com/@greut/sharing-templates-between-php-and-javascript-in-laravel-a5e07b43be24

@markusjwetzel
Copy link
Contributor

Great article! I added a link to your article in the readme file. 👍

@marijoo
Copy link

marijoo commented Feb 25, 2019

@greut @markusjwetzel This approach does not work with the helper function {{lang 'message' }}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants