Contact

admin

About Me · Send mail to the author(s) E-mail · Twitter

At GROSSWEBER we practice what we preach. We offer trainings for modern software technologies like Behavior Driven Development, Clean Code and Git. Our staff is fluent in a variety of languages, including English.

Feed Icon

Tags

Open Source Projects

Archives

Blogs of friends

Now playing [?]

  1. Grum – Transport
  2. Grum – Someday We'll Be Together
  3. Grum – LA Lights
  4. Grum – The Really Long One
  5. Grum – Want U
Audioscrobbler/Last.fm

ClustrMap

New DasBlog Macros for On-Page Navigation and Post Modification Date

Posted in dasBlog at Sunday, December 30, 2007 4:08 PM W. Europe Standard Time

Per Torsten's request I created a couple of new macros for DasBlog.

On-Page Navigation

Torsten wanted to enable on-page navigation to the next and previous post, comparable to the mail navigation introduced in Outlook 2007:

 Outlook 2007 Navigation

Previous and Next Macros Sample OutputThe OnPageNextLink and OnPagePreviousLink macros display a link to the next and previous post on the current page in list view. Please note that these macros don't create link across pages. For example, the last post on the page doesn't have a previous link, even though there might me older posts.

Because I use URL rewriting to get rid of /default.aspx in my home page URL an issue with the browser reloading the whole page came up, making is necessary to create a couple of overloads:

  • OnPageNextLink(navigationText)
    OnPagePreviousLink(navigationText)
    Renders a link to the next/previous post on the current page. The CSS class for the anchor tag is next and previous, respectively. The navigationText parameter takes a string containing different locale versions of the text to be displayed as used in the LocalString macro.
    The first post on the page does not have a "next" link, whereas the last post on the page does not have a "previous" link.
  • OnPageNextLink(navigationText, removeUrlFragmentRegex)
    OnPagePreviousLink(navigationText, removeUrlFragmentRegex)
    Same as above. The regular expression specified by the removeUrlFragments parameter will be used to remove parts from the URL.
    If you use URL rewriting for /default.aspx, the regular expression is default\.aspx$.
  • OnPageNextLink(navigationText, cssClass, removeUrlFragmentRegex)
    OnPagePreviousLink(navigationText, cssClass, removeUrlFragmentRegex)
    Same as above, but you are able to set the CSS class explicitly.

Example

In your itemTemplate.blogtemplate, embed the macro markup for the on-page navigation. Note that in this example uses a regular expression to remove a tailing "default.aspx" from URLs:

<% OnPageNextLink("Next|DE:Weiter", "default\.aspx$") %>
<% OnPagePreviousLink("Previous|DE:Zurück", "default\.aspx$") %>

This will render the following HTML for /default.aspx which can be styled using CSS:

<a class="next" href="http://www.therightstuff.de/#<some-guid>">Next</a>
<a class="previous" href="http://www.therightstuff.de/#<some-guid>">Previous</a>

The HTML for URLs other than /default.aspx:

<a class="next" href="http://www.therightstuff.de/default,page,1.aspx#<some-guid>">Next</a>
<a class="previous" href="http://www.therightstuff.de/default,page,1.aspx#<some-guid>">Previous</a>

Post Modification Date

Another requirement Torsten had is to be able to display the modification date of a post. For unedited posts this date is equal to the creation date, which we use to decide whether to display the modification date or not. There are a couple of overloads:

  • Modified
    Displays the modification date if the post has been modified. (Comparable to the When macro.)
  • FormattedModified(format)
    Displays the formatted modification date if the post has been modified and appends the timezone the blog is hosted in. (Comparable to the FormattedWhen macro.)
  • FormattedModifiedBare(format)
    Displays the formatted modification date if the post has been modified and does not append the timezone the blog is hosted in. (Comparable to the FormattedWhenBare macro.)
  • IfModified(expression)
    Displays localized text if the post has been modified. The expression parameter takes a string containing different locale versions of the text as used in the LocalString macro.

Example

In your itemTemplate.blogtemplate, embed the macro markup for the post creation date and the modification date:

<% LocalString("Posted in|DE:Veröffentlicht unter") %> <% categoryLinks %>
<% LocalString("at|DE:am") %> <% FormattedWhen("f") %>
<% IfModified(" and changed at |DE: und verändert am ") %><% FormattedModified("f") %>

This will render the following HTML for an edited post:

Modification Date

Now Playing [?]: Ulrich SchnaussGoodbyeStars

All comments require the approval of the site owner before being displayed.
(will show your gravatar icon)
 
[Captcha]Enter the code shown (prevents robots):

Live Comment Preview