Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9181279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:16:26+00:00 2026-06-17T18:16:26+00:00

Trying to load a particular template based on what :server-name returns in the request:

  • 0

Trying to load a particular template based on what :server-name returns in the request:

(ns rosay.views.common
  (:use noir.core)
  (:require [noir.request :as req]
            [clojure.string :as string]
            [net.cgrand.enlive-html :as html]))

(defn get-server-name
  "Pulls servername for template definition"
  []
  (or (:server-name (req/ring-request)) "localhost"))

(defn get-template
  "Grabs template name for current server"
  [tmpl]
  (string/join "" (concat [(get-server-name) tmpl])))

(html/deftemplate base (get-template "/base.html")
  []
  [:p] (html/content (get-template "/base.html")))

It works for localhost which returns /home/usr/rosay/resources/localhost/base.html, but when I test against a different host say “hostname2” I see where get-template is looking at /home/usr/rosay/resources/hostname2/base.html but when it renders in the browser it always points back to ../resources/localhost/base.html.

Is there a macro or different way to handle this use-case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:16:28+00:00Added an answer on June 17, 2026 at 6:16 pm

    As mentioned in the comments, deftemplate is a macro that defines the template as a function in your namespace – only once, when it’s first evaluated. You can easily write some code to lazily create the templates, and eliminate some of the overhead by caching the template once it’s created:

    (def templates (atom {}))
    
    (defmacro defservertemplate [name source args & forms]
      `(defn ~name [& args#]
         (let [src# (get-template ~source)]
           (dosync
            (if-let [template# (get templates src#)]
              (apply template# args#)
              (let [template# (template src# ~args ~@forms)]
                (swap! templates assoc src# template#)
                (apply template# args#)))))))
    

    In your case you’d then be able to say (defservertemplate base "/base.html"....

    You can probably tidy this up a bit. All you really need to know is that deftemplate just calls template, and you can use that directly if you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting the following exceptions when trying to load a particular layout file in
I'm trying to load text of all divs that have a particular class into
i m trying load UIImages from server asynchronously in UITableViewCell. My code worked fine
I am trying to load a json store when I click on a particular
$([littleBox]).load(ajax.php?eid=+$(this).attr(littlebox)); the $(this).attr(little box) portion of the code returns undefined . I'm trying to
I'm trying to determine if I can use a line like: if request.xhr? do
Basically I'm trying to find all the elements with a particular class name and
I am trying to integrate this particular app in my website. When I load
I have a problem with out of memory when I'm trying load a few
Trying to load content into a div, then on click load the previous content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.