Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple variable substitution (with example) in meta tag throwing NullPointerException #137

Open
JMacLulich opened this issue Jan 4, 2016 · 2 comments

Comments

@JMacLulich
Copy link

Hi,

I'm loving enlive, however I have a weird problem with finding and replacing variables inside meta tags.

This is my html.

<meta property="og:title" content="${event-title}" />

When I apply this transformation:

(at (html-resource "templates/page-meta.html") [:meta] (replace-vars {:event-title "hello"}))

assuming the HTML content is in the file templates/page-meta.html I get this problem:

1. Unhandled java.lang.NullPointerException
   (No message)

                  Matcher.java:  701  java.util.regex.Matcher/quoteReplacement
                    string.clj:   67  clojure.string/replace-by
                    string.clj:  106  clojure.string/replace
               enlive_html.clj:  677  net.cgrand.enlive-html/replace-vars/substitute-vars
               enlive_html.clj:  683  net.cgrand.enlive-html/replace-vars/fn/iter/fn
                  LazySeq.java:   40  clojure.lang.LazySeq/sval
                  LazySeq.java:   49  clojure.lang.LazySeq/seq

Without going through the enlive sources, which I don't really have time for, I'm at a loss to explain this problem?

Any ideas?

Cheers, Jason.

@JMacLulich
Copy link
Author

Other tags like <a href...> work, i.e. this works.

<a href="#" id="fb-share" class="btn-action" onclick="facebookShare('${event-code}');">

Just not meta so-far?

This is a bit of a show stopper...the only other way I can see around this is to set the attribute content directly after doing more preprocessing up-front, but that's really annoying.

@mavbozo
Copy link

mavbozo commented Apr 20, 2018

@JMacLulich
do you have other tags with vars in them in your page-meta.html?

I find this problem if there are other meta tags with vars in them and the replacement map does not contain all the needed vars to be substituted.

the solusion is either more specificity to the selector e.g. [[:meta (attr= :propery "og:title"]]

or make sure in the replacement map contains all vars for all tags

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants