Handlebars formatting in NetBeans - netbeans

I'm using NetBeans as my IDE for a Ember.js project. When I create handlebars templates in my app like below the code highlighting doesn't work correctly.
<script type="text/x-handlebars">
<div>
</div>
</script>
Normally, when I'd select the first div, it and its matching end tag would highlight yellow, but this doesn't work. Since its inside the handlebars script tag both are highlighted red as errors and don't match together. This makes writing complex templates kinda annoying as it can be difficult to pinpoint syntax errors.
Is there anyway to get NetBeans to highlight inside the handlebars tag as if its regular html?

One option, until Netbeans implements this enhancement, is to add the following script tag in index.html immediately after your reference to jQuery:
<script src="js/libs/jquery.js"></script>
<!-- use following line to change script type to 'text/x-handlebars' -->
<script>jQuery('script[type="text/html"]').attr('type', 'text/x-handlebars');</script>
This is a variation of the answer provided by GCoda.

I had the same problem and tried various non satisfying fixes.
In the end I figured the best solution is simply to change the script's type attribute to text/html:
<script type="text/html">
<div>
</div>
</script>

I got same problem. And i just used a some kind of postprocessing, i am using node.js, so i did res.send(data.replace(/type="text\/html"/g,'type="text/x-handlebars"')); on my / page.
I think you can do something similar in you language, and ofcource this is not a fix, just an ugly trick to make developing more easy. Dont keep it in production.

Related

Why don't the official FancyBox 4 bind examples work?

None of the bind examples in the documentation work - https://fancyapps.com/docs/ui/fancybox/api
The standard constructor examples work great, but anything that requires binding does not work. There is no error, but the gallery lightbox doesn't work - clicking an image just opens the image as a link. Here is the exact example code with markup:
<div id="gallery">
<a href="https://lipsum.app/id/1/800x600">
<img src="https://lipsum.app/id/1/300x225" />
</a>
<a href="https://lipsum.app/id/2/800x600">
<img src="https://lipsum.app/id/2/300x225" />
</a>
</div>
<script>
Fancybox.bind("#gallery a", {
on : {
ready : (fancybox) => {
console.log(`fancybox #${fancybox.id} is ready!`);
}
}
});
</script>
That console log never fires.
I'm importing FancyBox like this:
import { Fancybox } from '#fancyapps/ui';
I've tried searching around, but very little info on FancyBox 4 other than official docs and it's frustrating as they don't work. I've tried some of the examples in showcase also, and the same deal. If it's binding, it won't work and no errors are shown. Anyone have any insight into this?
Thanks,
Tom
It works perfectly fine. Since you did not provide a live demo (or at least a full HTML code), then it just not possible to help you.
It is so frustrating to read comments like this, no demo, no useful info, nothing. Maybe you did not include JS file, I do not know ... I would love to help you and to improve documentation, but, sorry, your comment is not helpful at all.
Fancybox is designed to be as easy to use as possible, all you have to do is:
Include two files - CSS and JS file (to get Fancybox object).
Add data-fancybox attribute to your links (or to call Fancybox.bind("YOUR_SELECTOR");)
Thats it! It can not be any simpler.
Sorry, it should have been a much clearer question. I didn't include a demo because it's a big wordpress site in production. It was giving me no useful feedback or errors or anything like that. I build websites day in and day out, so assumed it wasn't just me making some incredibly stupid mistake like a typo or something. I genuinely spent a lot of time on this, it wasn't me being lazy and just posting on stack overflow straight away...
It was me being stupid though.
In the process of making a demo to show you, I found the problem and (as you already know!) it's my mistake. I was able to make fancybox work by instantiating it straight away in my js, but binding (and therefore galleries etc) was not working.
The reason was the javascript was included in the head of the html document before the markup instead of at the bottom of the html document before the closing body. There was nothing for the js to bind to when it was executed.
I wouldn't normally include javascript in the head either but it's a wordpress project and because of some plugin, it's required there. Fancybox 3 worked with js in the head, but I suspect it might be jquery being more forgiving than native js with it's binding to DOM elements?
So, yes, entirely my fault. I was following the steps of the installation and startup guide almost exactly, but that inclusion of the js file in a slightly unusual (or bad practice at least) place was what caused all the issues.

Netbeans: Syntax Highlighting -- multiple languages per file

The majority of the pages I author contain both HTML and PHP. It would appear that in Netbeans you can have syntax highlighting for one or the other by setting the associated file types.
Coming from Notepad++, I've always taken for granted the fact that I could use php, css, html, javascript all in one file and retain syntax highlighting for all of them.
Is this possible in Netbeans?
I think the answer here is that Netbeans DOES support multiple language, but it will only get it right if there's something hinting at the "inner" language. When I exit PHP with ?> NetBeans tends to format what comes before the next <?php as HTML automatically. Not sure if that is working for you. Maybe you were trying to get highlighting in a string like $output = "<some><html";. I think you can imagine why that second one wouldn't work.
For JS, for example, it seems to look for the <script type="text/javascript">, and stuff inside gets the JS highlighting even if the file type is PHP.
This other question has a great solution for "tricking" Netbeans into rendering your JS output by PHP into being formatted, even when your code doesn't have a <script type="text/javascript"> tag.

HTML comment tag <!-- --> Removed in CQ5

I'm using Rich Text Editor with MiscTools plugin to edit text in CQ%
However when I open the HTML editor and create sth like this
<div id="test">Test <!-- Test Comment --></div>
the CQ rewrites it to after switch back to HTML mode and source edit mode
<div id="test">Test </div>
Is it possible to keep HTML comment tag <!-- --> in the source code?
Thank you for answer my question
I would suggest taking it out of the div and see if that works.
In CQ5.4-5.6.1 (not sure about latest version AEM6), the Rich Text Editor intentionally strips out all HTML comments. The only way to stop it from doing this is to modify the product javascript source code in WhitespaceProcessor.js. However, allowing HTML comments in this way wouldn't be recommended as it hasn't been fully tested it might cause other errors. If you still need this feature, then you might consider contacting Adobe Customer Care to request it to be officially added to the product.

Incorrect MIME type for GET requests

I've been using the Lift Web Framework as a REST only service for quite a while, but I need to use it as a stand alone tool now.
<lift:surround with="default" at="content">
<head>
<script data-lift="with-resource-id" src="/test.js" type="text/javascript"></script>
</head>
<h2>Welcome to your project!</h2>
<p><lift:helloWorld.howdy /></p>
</lift:surround>
I have the above very basic Lift template. The problem is when I view it in the browser something is adding an <?xml> DOCTYPE and the browser defaults to interpreting the resource as XML instead of plain HTML.
How do I tell Jetty/Lift that my static file is HTML?
Sounds like you may be using the XHTML doctype. In your Boot.scala file, you may want to try adding:
LiftRules.htmlProperties.default.set((r: Req) =>
new Html5Properties(r.userAgent))
That should set your application to use HTML5, and should turn off adding the <?xml... encoding header.
Also, as #VasyaNovikov mentioned, the lift: prefixed tags are an older construct (even though a lot of documentation still mentions them). They still work but will have some issues with HTML5. It is recommended to use either of the equivalent forms:
Original:
<lift:surround with="default" at="content">...</lift:surround>
HTML5:
<span data-lift="surround?with=default;at=content"></span>
<span class="lift:surround?with=default;at=content"></span>
If you want to use the lift: variety, the biggest issue you'll find is that in HTML5 the tags and attributes are converted to lowercase, so <lift:helloWorld.howdy /> will be interpreted as <lift:helloworld.howdy />, and Lift will not find the snippet. Using <span data-lift="helloWorld.howdy"></span> should allow you to work around that.
Maybe adding the header will help?
<html>
<head>...
Example:
https://github.com/lift/lift_25_sbt/blob/master/scala_29/lift_basic/src/main/webapp/index.html
In general, you use a very old approach to templates, with custom tags <lift:surround>, <lift:helloWorld> and such. Where did you get them? I suggest to use the new template style like in the link I posted.

jQuery Tmpl removes TR tag content when not wrapped by TABLE tag

Upon migrating my old web interface with extensive use of jQuery Tmpl, some of my templates have ceased to work. Further investigation shows that the templates not working are the ones starting and ending with TR tags (i.e. table rows getting appended to an existing table). The source text just gets removed by the jQuery Tmpl script! If I use the TR tags in a broader context like wrapped in a table etc everything works just fine, but as soon as they are used in an isolated template, they get wiped out.
working example:
<script id="workingTemplate" type="text/x-jQuery-tmpl" >
<table>
<tr><td>this works</td></tr>
</table>
</script>
not working example:
<script id="notWorkingTemplate" type="text/x-jQuery-tmpl" >
<tr><td>this does not work</td></tr>
</script>
The first example renders the full HTML code when checking with Firebug, the latter renders an empty SCRIPT tag.
The difference between the old and the new web interface that could in any way be related to the templating is a change from jQuery 1.5.2 to 1.8.2. I haven't tried running anything below 1.7.2 since this is where the .on() function got added, and the new framework has an extensive use of this method.
Are there any workarounds for this problems except the most obvious (= changing templating framework to something still maintained)?
EDIT:
When loading the template from a string, the content stays intact,
$.template( "tableRowTemplate",'<tr><td>this works</td></tr>');
$.tmpl("tableRowTemplate", data).appendTo('TABLE#mytable TBODY');
but is unfortunately no good for me since my templates are a tad more complicated than the examples (server side dynamics etc...). It does give some hints though. Obviously, it is the initialization of jQuery Tmpl that removes the content if it does not comply with something to me unknown. Maybe jQuery.fn.domManip?