Closed holyjak closed 10 years ago
You are mixing two concepts here. A template is not suppose to have a sub selector. Its an internal implementation detail that makes it work. I don't see why you are even using the deftemplate in this case. It is not doing anything for you. You would just use defsnippet.
Instead of this:
(defsnippet kiootest-one "kiootest.html" [:#contentOne] [_]
{[:#name] (content "Kioo")})
(deftemplate kiootest "kiootest.html" [_]
[:body] {[:body] (substitute (kiootest-one _))})
;; ^- custom root selector
;; ^- inside the selected <body..>..</body>, match the body element itself
(om/root #(om/component (kiootest %)) (atom {})
{:target (. js/document (getElementById "om-shop-list2"))})
Is there a reason this doesn't work
(defsnippet kiootest-one "kiootest.html" [:#contentOne] [_]
{[:#name] (content "Kioo")})
(om/root #(om/component (kiootest-one %)) (atom {})
{:target (. js/document (getElementById "om-shop-list2"))})
Thanks a lot! I mistakendly believed that snippet can only be used inside a template.
Sorry for wasting your time :-)
I had made the same assumption, and spent some hours trying to figure out what was happening.
May I kindly suggest to explain in the README what deftemplate does or return, as opposed to defsnippet. Purely out of compassion, please.
@danielsz - I added the template and snippet section to the Readme.md. If you could, please take a look and let me know if you think it needs to be more clear.
Yes! This tells us what we should know regarding snippets and templates. Nice job. Thank you!
On a more general note, I would argue that the term "kioo component" is unfortunate. Users come to kioo after having spent some time with a Clojurescript React library, which already refers to its artefacts as components
. In my mind, for example, Om and Reagent wrap React components, while Sablono and Kioo provide a mechanism to generate React-approved tags and attributes. Talking about "kioo components" causes semantic overload, even though I'm sure you can make the case for them.
I spent considerable time finding out why
(deftemplate ... {[:body] (content ..)})
does nothing and would like to help other users avoid the same problem. (Though hopefully only few need it.)For more info/background, see the blog post http://theholyjava.wordpress.com/2014/04/08/kioo-how-to-replace-the-whole-body/ (feedback warmly welcomed)