if I right hiccup has no template inheritance. How can I make it work thatI made one template for several pages ? or can I better use selmer ?
If I can better use selmer. How must I translate this : '
<script type="text/javascript" src="js/jquery-ui-1.10.2.custom.js"></script>
i've never seen anyone offended before for saying "hey guys." where I was raised and where I'm living now, it's inclusive of anyone male/female whatever. just a colloquial that everyone is used to. i know as programmers we are pretty pedantic but shouldn't make anyone feel bad for speaking the way they're used to talking
@roelof: Hiccup is dealing with HTML as a data structure. So if you want to have a "template", in Hiccup that would be a function that returns a data structure that is partially the same no matter what you pass it, and partially depends on what you pass it. So, like, if your template is all the header and footer stuff, and you want to put some content within that template, write a function that accepts that content (as a Hiccup data structure) as the argument and returns the data for the whole page. It's just data structures, so it should be easy.
Where do people put clojure snippets on the web? Like codepen or jsfiddle or gist.
Gist had all the features i wanted (doesn't it always?) nvm.
@jeff.terrell: sorry I do not fully understand you.
Let's say I have a home page and a contact page which shares the same header and footer
How would I do that ?
@chedgren: Most of us use refheap. You can find it here : https://www.refheap.com/
@roelof: Something like this:
(defn content->page [content]
[:html
[:head ...]
[:body
[:div.content content]
[:div.footer ...]]])
You'd have to fill out the details of the header and footer. But then you could say e.g.:
(content->page [:p "Hello world!"])
β¦to get a full page with that content. Make sense?Yeah, basically in hiccup template inheritance can be done with language mechanisms - function composition and higher order functions.
oke, so I can make functions for all and when I want to use them I could make a function call with the right parameters
I hope I can make then a template like this page that way : https://laboutique.lemonstand.com/
I will play and experiment with the idea
thanks for the idea
I already have figured out how to call css and js files
In hiccup do they also have to be in the resoures directory
?
I don't think hiccup cares about that, but resources/ is the standard place to put them.
and do I understand it right I have to do all the templating of all the pages in one file
No, why.
You can split the functions as you wish
Just like you would with Clojure source
But I guess grouping things by a page is a good idea.
I thought so by the example jeff gave
Templating in hiccup is just writing Clojure functions
That return hiccup vectors
This is the first time I try with multiple sources
So anything you would do with Clojure functions
Applies here
You may put everything in one file
Or makes namespaces to group related things
It's up to you
oke, i will try to find some examples of using namespaces
Right. You can have a different function for the header content, for example. Or you could have multiple different templates. Or whatever you want. It's just data.
Also, you don't have to put hiccup templates in resource directory, you can have them in the same source directory the rest of code, since it's code like any other.
But that's again - matter of taste.
I usually keep my hiccup in the source directory under some namespace like project-name.templates.page-name
or something.
Yes, good point @jaen. To clarify, I think resources/
is a good place to put CSS and JS files, but I probably wouldn't put any Clojure functions (like my content->page
example above) in resources/
. Code goes in src/
.
oke, and I found here a example of what you are trying to tell me : https://github.com/yokolet/hiccup-samples/blob/master/src/
Yup, that looks pretty sensible to me, though I usually wrap each function-template with the` html` macro, not just the top level one, but I'm unsure if that's wrong or right - that's just what I do.
jaen: oke, do you have a example where I can look at
No, but that would be the same as there.
The difference would be I would be doing
(def template []
(hiccup/html5 [:div "some hiccup"]))
instead of
(def template []
[:div "some hiccup"])
in each template.oke, thanks everyone
time to experiment with this and hopefully I have a page ready soon
last question I hope. How do I translate this ` <meta charset="UTF-8"> <meta name="Description" content=""/>`
Like any other tag, really
[:meta {:charset "UTF-8"}]
[:meta {:name "Description" :content ""}]
it's always
[:tag-name {:attributes "go here"} "some content" 123]
oke, thanks
@bhauman: devcards is pretty awesome π just wondering if you knew how to get some jquery library initializing from the dom to play nicely with reagent
@naomarik: that's more of a React thing. Read up on how to create react components and the lifecycle https://facebook.github.io/react/docs/component-specs.html
https://github.com/Day8/re-frame/wiki/Using-Stateful-JS-Components might be helpful