Jahia Print & E-mail Templates

Nov 09, 2011
Oshyn Labs

I want to share a possible implementation of how to do a print friendly view and email functionality in Jahia V6. I want to share this because these two types of functionality are very common across websites and Jahia can be used to easily implement them.


Print Friendly View

The print view is a print friendly view of a webpage. The idea of that view is to give the user the option to print only the important information contained in a web page excluding some navigation components such as the header and the footer.

I suggest you read my post "Jahia WCM Quick Review: Maven, Templates and Navigation" if you are new with Jahia.

Consider that we have a jsp page that represents a template in Jahia and looks like this:


<template:template>
    <template:templateHead>
        <script language="javascript" src="${jahia.includes.webPath['main.js']}"></script>
        <link rel="stylesheet" type="text/css" href="${jahia.includes.webPath['main.css']}" media="screen"/>
    </template:templateHead>
    <template:templateBody>    
        <template:include page="common/header.jsp" />
        <!-- Start of Content Section -->

        <!-- End of Content Section -->
        <template:include page="common/footer.jsp" />
    </template:templateBody>    
</template:template>


The idea of the print view is to have a similar above template that shows only the information section of the web page. We can achieve that by calling the same page with different parameters in order to hide those sections that we do not want to include.

The print view link can be done by using a javascript function similar to this one:


window.open(window.location.href + “?print=true”);


In the template we can look if the request parameter print exists and change the stylesheet if necessary and also it is possible to include a different jsp when that parameter is in the request using the taglib template:include.

Following is a print friendly view sample where the header, footer, and navigation are not showed.



E-mail

It is common for new websites to have a link that says "Send Email" in order to send someone else an email containing the link and title of a webpage that has interesting information, and it is usually possible to include some user text in the email. Jahia can be used to implement that functionality by using the following Jahia instructions ${jahia.page.title} and ${jahia.page.url}, where jahia.page.title returns the title set by the editor and jahia.page.url returns the url of the page.

The idea is to create a jsp file in the Jahia template set that is going to handle the email functionality. That page can be called from the template in the following manner:


<a href="javascript:popup('${jahia.includes.webPath['mailTemplate.jsp']}?pageTitle=${jahia.page.title}&pageUrl=${jahia.page.url">send</a>


Where the popup functions is a javascript function that is going to use window.open(), and the url parameter contains the Jahia expression language instruction ${jahia.includes.webPath['mailTemplate.jsp']}, where mailTemplate.jsp is the jsp file that is going to handle all the send email logic using standard java libraries.

Notice that it is very important that this mailTemplate.jsp file should exist in the current Jahia template set project, but should not exists in the templates.xml file declaration like shows the following configuration file.


<templates default="home" homepage="Home">
    <template name="home" display-name="Home page" filename="home.jsp" page-type="my_templates:home"/>
   <template name="twoColumns" display-name="Two Columns" filename="twoColumns.jsp" page-type="my_templates:twoColumns"/>
</template-set>


Following is a screenshot of an Email template, where you can enter the source and destination e-mail, a subject, a text field where you can include a note to the e-mail, and the name of the page.