Queue the Heow
the eternal search for simplicity
meetings blogs news home
<< January 10, 2011 | Home | January 12, 2011 >>

Templating Enlive

Selectors for templating HTML's metadata

Christophe Grand's Enlive is a great tool, it makes HTML generation and parsing a breeze, that is if you're moderately familiar with CSS selectors.

When templating (or seaching) HTML/XML, most of the time you will be selecting by ID or CLASS, but for those times when you're not, such as making the HTML metadata SEO-friendly, you're going to need a special selector.

The HTML metadata looks like this:

 <meta content="example I want to replace" name="description" />

If what you want to change is the content, then it's not selectable by either CLASS or ID.  You just have to dig in a bit and use a boolean along with a few of Enlive's helper funcitons.  Here is the code to do a template replacement of the metadata's content:

[(and (enlive/has [:meta]) (enlive/attr-has :name "description"))] (enlive/set-attr :content "Word's Eye: Converting Simple English Into 3D Scenes")

Social Bookmarks :  Add this post to Slashdot    Add this post to Digg    Add this post to Reddit    Add this post to Delicious    Add this post to Stumble it    Add this post to Google    Add this post to Technorati    Add this post to Bloglines    Add this post to Facebook    Add this post to Furl    Add this post to Windows Live    Add this post to Yahoo!