Conditional transforms

32 views
Skip to first unread message

Toni Tuominen

unread,
Oct 18, 2012, 8:36:27 AM10/18/12
to enf...@googlegroups.com
Hey,

I would like to have a transform that leaves the content in the template alone if the value passed to the transform is nil. How should I go about implementing this?

Example:
(defaction foo [text]
  ["#bar"] (em/maybe-content text)

So if text is nil the content in #bar is left alone.

Thanks in advance,
Toni

Creighton Kirkendall

unread,
Oct 18, 2012, 9:03:40 AM10/18/12
to enf...@googlegroups.com
I think I would create a nil transform that does nothing.

(defn maybe-content [val] 
(if 
(em/trans [pnod] ))

(defaction foo [text]
["#bar"] (if (nil? text)
(nil-trans)
(em-context
 

--
 
 
 

ckirkendall

unread,
Oct 18, 2012, 9:08:39 AM10/18/12
to enf...@googlegroups.com
Sorry hit enter on accident.

(defn maybe-content [val]
      (if (nil? val)
          (em/trans [pnod] )
          (em/content val)))

Note: em/trans is a macro for creating custom transforms, by passing an empty body basically you are creating nil transform.

CK


Toni Tuominen

unread,
Oct 18, 2012, 9:20:50 AM10/18/12
to enf...@googlegroups.com
Thanks, worked like a charm. Also thanks for writing enfocus, it's awesome.

- Toni
Reply all
Reply to author
Forward
0 new messages