{"id":122,"date":"2016-06-02T19:40:45","date_gmt":"2016-06-02T19:40:45","guid":{"rendered":"http:\/\/www.dimlucas.com\/?p=122"},"modified":"2016-11-27T14:02:18","modified_gmt":"2016-11-27T14:02:18","slug":"custom-html-elements","status":"publish","type":"post","link":"https:\/\/www.dimlucas.com\/index.php\/2016\/06\/02\/custom-html-elements\/","title":{"rendered":"Custom HTML Elements"},"content":{"rendered":"<p>Hi, everyone! We&#8217;re back to Aurelia and this time I&#8217;m going to show you how to build your own custom element just with HTML, without a view-model. Yes, that&#8217;s possible!<\/p>\n<p>There are many advantages to an HTML-only element, like, first and foremost, not having to use a view-model at all! This is particularly useful when your custom element does not implement complex business logic but you just need a quick component for your applications.<\/p>\n<p>Now, HTML-only custom elements bring us some good and some bad news.<\/p>\n<p>The good news\u00a0is that you can still add bindable custom attributes to your elements by adding them to the bindable attribute of the template element in a comma separated fashion:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\/\/my-element.html\r\n&lt;template bindable=&quot;attributeOne, attributeTwo, attributeThree &quot;&gt;\r\n\u2026.\r\n&lt;\/template&gt;\r\n<\/pre>\n<p style=\"margin: 0in; font-family: Calibri; font-size: 11.0pt; color: black;\">\n<p>&nbsp;<\/p>\n<p>You can then use it like that:\u00a0<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;require from=&quot;.\/my-element.html&quot;&gt;&lt;\/require&gt;\u00a0\r\n&lt;my-element attribute-one=&quot;someVar1&quot; attribute-two=&quot;someVar2&quot;&gt;&lt;\/my-element&gt;\u00a0\r\n<\/pre>\n<p>\u00a0<br \/>\nYes, Aurelia does the conversion from camelCase to dash-case on its own all the time. That comes in handy.\u00a0\u00a0<br \/>\nOne thing you might have noticed in the example above is that, in order to use an HTML-only element, you also need to include the &#8220;.html&#8221; extension in your path. That happens mainly due to the absence of a view model.\u00a0<br \/>\n\u00a0<br \/>\nThe bad news is that HTML-only custom elements do not support two-way binding by default. That means that, if you want two-way binding functionality, you need to explicitly state it. I will demonstrate this with a simple example as it can be very confusing to newcomers:\u00a0<\/p>\n<p>The HTML-only element:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/dimlucas\/fea3760368d28207203fcd34e16b3c51.js\"><\/script><\/p>\n<p>And how we can use it:<\/p>\n<p><script src=\"https:\/\/gist.github.com\/dimlucas\/8907313cf8afb21bcb1563382c00d237.js\"><\/script><\/p>\n<p><script src=\"https:\/\/gist.github.com\/dimlucas\/17459f9206b7edfc9c46249b7af81204.js\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, everyone! We&#8217;re back to Aurelia and this time I&#8217;m going to show you how to build your own custom element just with HTML, without a view-model. Yes, that&#8217;s possible! There are many advantages to an HTML-only element, like, first and foremost, not having to use a view-model at all! This is particularly useful when [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[49],"tags":[],"_links":{"self":[{"href":"https:\/\/www.dimlucas.com\/index.php\/wp-json\/wp\/v2\/posts\/122"}],"collection":[{"href":"https:\/\/www.dimlucas.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dimlucas.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dimlucas.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dimlucas.com\/index.php\/wp-json\/wp\/v2\/comments?post=122"}],"version-history":[{"count":5,"href":"https:\/\/www.dimlucas.com\/index.php\/wp-json\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":127,"href":"https:\/\/www.dimlucas.com\/index.php\/wp-json\/wp\/v2\/posts\/122\/revisions\/127"}],"wp:attachment":[{"href":"https:\/\/www.dimlucas.com\/index.php\/wp-json\/wp\/v2\/media?parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dimlucas.com\/index.php\/wp-json\/wp\/v2\/categories?post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dimlucas.com\/index.php\/wp-json\/wp\/v2\/tags?post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}