Snippets execute computer code that rewrites the DOM elements in a section of the page (or in some cases on the who page.)
Snippets are invoked via the data-lift
attribute on an HTML
element. For example:
<div data-lift="ignore">This div will not be displayed</div>
Parameters can be passed to a snippet using URL syntax:
<div data-lift="twitter?user=dpp&rpp=6"></div>
Which will invoke the Twitter snippet and insert a Twitter feed for user app
onto the page with the 6 more recent Twitter posts.
Available snippets:
Just display the most recent 15 blog posts in a fixed template. For example:
<div data-lift="blog.simple"></div>
Take all the pages on the site marked as blog posts and bind the information about them into the places in the template.
For example:
<ul data-lift="blog.posts?max=15">
<li data-post="item">
<h2><a data-post="link" href="#">Blog Post</a></h2>
<h4><span data-post="date">2012/12/14</span></h4>
<div data-post="shortcontent">Post Content goes here</div>
<div data-post="more"><a href="#">Read More...</a></div>
</li>
</ul>
The maximum number of blog posts to display. If omitted, all blog posts are listed.
The DOM element that each post will be bound to. For each blog post, an instance of this DOM will be generated.
The href
attribute of this element will be set to the link to the blog post
and the body of this element will be set to the title of the blog post.
The date of the blog post will be put in the body of this element
The short content (about 700 characters) will be placed in the body of this element.
If the short content was truncated, the DOM node with the data-post="more"
attribute will be displayed. Any <a>
tag inside the data-post="more"
DOM node will have its href
attribute set to a link to the blog post.
Insert a Twitter feed onto the page.
For example:
<div lift-data="twitter?user=dpp></div>
The ID of the Twitter user for the feed. If not provided, will default to "_telegram".
Number of items to show in the feed. Default = 4.
How frequently to update the feed, in milliseconds. Default = 30000.
The height of the control on the page. Default = 300.
Background color for the display shell. Default #bfbfbf
The color of the display shell. Default #000000
The background color for Tweets. Default #ffffff
The text color for Tweets. Default #000000
Insert a Google search box that will search just this site:
<form data-lift="search" style="float: right"></form>
Test an attribute and display the DOM if the attribute or extra info exists and is true
.
To test if an attribute exists and it true
:
<div data-lift="if?toTest=foobar">
Yes, foobar is defined!
</div>
To test is Extra Info exists (the value is defined, does not test the value):
<div data-lift="if?extra=author">
The page has an author: <span data-lift="page_info?name=author">Author name here</span>
</div>
To test is Extra Info exists and the value is true:
<div data-lift="if?extra_true=has_blog">
<div data-lift="blog.simple"></div>
</div>
To test is Extra Info exists and the value equals another String:
<div data-lift="if?extra_eq=author&value=david+pollak">
A blog post by David Pollak, yay!
</div>
Sometimes you want stuff in a part of the page template, but it's part of the main page and you want to re-write the page such that stuff at the top of your content page is moved to a part of the template.
For example, if your template has a page_header
<div>
like:
<div class="page-header" id="page_header">
<!-- if you've got a header, put it here -->
</div>
And the top of your content looks like:
<div id="left_side">
<div class="hero-unit">
<h1><a href="https://twitter.com/dpp">David Pollak</a>'s blog... <small>and such.</small></h1>
Lots of DPP's thoughts here...
</div>
…
</div>
Or:
<div id="left_side">
<h1>This is my page, dude</h1>
<p>Stuff</p>
</div>
Then move_top
will rewrite as such:
<div class="content" data-lift="move_top?from=left_side&to=page_header">
<div class="page-header" id="page_header">
<!-- if you've got a header, put it here -->
</div>
<div id="left_side">
<h1>This is my page, dude</h1>
<p>Stuff</p>
</div>
</div>
To:
<div class="content">
<div class="page-header" id="page_header">
<h1>This is my page, dude</h1>
</div>
<div id="left_side">
<p>Stuff</p>
</div>
</div>
move_top
looks at the first Element in the from
DOM element
and if it's a header tag (e.g., <h1>
, <h2>
, etc.) or it
has the CSS class page-header
or hero-unit
,
it will be removed from the from
DOM and inserted into the to
DOM.
Put additional markup in the <head>
section of the HTML markup.
Useful to include external resources such as style sheets.
For example:
<link data-lift="head" rel="stylesheet" href="/css/custom-theme/jquery-ui-1.8.16.custom.css" type="text/css">
Put additional markup at the end of the <body>
section of the HTML markup.
Useful to put scripts on the bottom of the page so the page loads faster.
For example:
<script data-lift="tail" type="text/javascript">
alert("The page is loaded");
</script>
Inserts a Disqus forum on the page.
For example, in the /templates-hidden/post_include.html
add the line:
<span data-lift="xform" data-css="#after-content *">
<span data-lift="disqus?shortname=dppblog"></span>
</span>
<span data-lift="xform" data-css="#after-content [id]">disqus_thread</span>
The outer xform
puts the inner span under the blog post on your page. The
inner disqus
inserts the correct JavaScript on the page to show the
Disqus comments for that page.
The second xform
sets the id
attribute so you can click through from
a comment count link.
For each link to a blog post, list the number of comments near the link.
For example, in the /index.md
file, include the line:
<span data-lift="disqus.count?shortname=dppblog"></span>
Insert a Google Map on the page at the location of the snippet.
For example:
My office is located at:
<div data-lift="google.map" data-address="541 8th St, San Francisco, CA">
</div>
", "render") -> Full(BaseSnippets.hTags),
Twitter Bootstrap requires
some special comments on the page to work nicely with Internet
Explorer. Insert the special comment into the <head>
section of the page
Twitter Bootstrap requires
some special comments on the page to work nicely with Internet
Explorer. Insert the special comment into the <body>
section of the page
Compute the text of the
<div data-lift="title">Post :: <div data-lift="menu.title">something</div></div>
Becomes:
<title>Post :: Playing with Telegram</title>
And gets placed in the <head>
section of the HTML page.
Do not include the HTML in the rendered output. For example:
<div data-lift="ignore">
I will not be included in the resulting page
</div>
Useful for having a comment in the markup as part of a work-in-progress.
Compute the site name via the site_title
Extra Info
and insert the value into the contents of the DOM node. For example:
<div data-lift="site.name" class="fruit_bat">Title Goes Here</div>
Becomes:
<div class="fruit_bat">David's Blog</div>
Surrounds the DOM elements with a template. This snippet is generally used to put "stuff" around the main part of the page. The stuff includes menus, FIXME
Inserts a template into the current page -- FIXME
Link to a named page -- FIXME
Choose one or more of the child nodes -- FIXME
Choose pages of a particular type -- FIXME
Generate Menus -- FIXME
Generate an id
<div>
-- FIXME
The title of the page -- FIXME
A set of menu items -- FIXME
Find a group of pages by type -- FIXME
Insert the JavaScript for Google Analytics -- FIXME
Insert content into surrounding template -- FIXME
List all blog posts and bind to a template by date -- FIXME
After the page is fully rendered, apply a CSS Transformation to the page -- FIXME
Insert values from Extra Info into the DOM