-
Notifications
You must be signed in to change notification settings - Fork 14
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
Examples of using gulp-data with json files and watch #19
Comments
Hi, @wjthomas9.
It's taken from my big gulpfile, so some variables will be undefined, if you just copy-paste it into your file, but the main idea should be understandable. |
@SkeLLLa : I don't understand your script, could you make it more understandable? |
Can someone bring here a bit of light? I'm stucked trying to use gulp-data on a gulp-watch, but get nothing but errors. Please, need some help. This example is quite complex, I've tried to resume it but still no luck at all. :-( |
First of all to read json files you'll need function like Then in watch task I add watcher (gulp-watch) on Also the case with template partials is handled. For example if partial template is changed (e.g. header template that is common for several pages) then I set variable |
thanks @SkeLLLa . I'm going to give it a try with 'swig' templates, perhaps I've been no luck with .jade. I think I must to change my approach to my problem. If I have no success with swig, will try 'twig' as your example. Thanks! |
@xanisu I think that it should work with both swig and twig. If you have no luck with twig also, then maybe post some of your gulp file code here, then may be I'll be able to help you. |
thanks @SkeLLLa Will let the results here once I've tested it. I appreciate your help. |
Finally I could get it working just with jade. Heres my working example:
Every time I change a jade template, I get an error message, but It still works, don't need to restart my gulp watch process. |
@xanisu What kind of error? Can you please tell what that error says? |
@SkeLLLa Here it is
But the watch process is still working so, everytime a modify my .jade file, I get this error on output window (running gulp command on webStorm), but changes are well compiled by jade, and the output html result is fine. |
@xanisu May be in your jade file you're referencing some fields that are not defined in your json. To make it clear you can try to experiment on simple jade template that has only one variable and a json file that also has one property. |
Can JSON data file have html tags with text? |
@jitendravyas Yep you can. But your front-end template parser needs to have a filter for parsing the HTML. For example, if you use something like Twig.js as your template parser, you can use the "escape" filter.
http://twig.sensiolabs.org/doc/filters/escape.html What template parser are you using? |
Might be nice to update the example for JSON use. It's been a while since I used Node and did web dev, I was confused why my template wasn't updating and assumed the template was caching, but it turned out to be the require call cached my file, I had to replace the require with fs and JSON.parse() like in the shared code above. Another thing that was not clear(partly |
Hi,
Do you have any examples of how to ensure templates get fresh data when saving a json file? It seems I have to stop and start gulp every time I make a change to a json file.
The text was updated successfully, but these errors were encountered: