August 24, 2010

Saving Images for the Web in Photoshop

Recently we ran into a problem where we had uploaded some images and they were using CMYK – which will not work on some browsers and can result in images not being shown or displaying as broken. To avoid this you can easily save your images in a format that is more ideal for the web (RGB).

To do this in Photoshop (CS4 shown, it’s similar for other versions) just do the following:

1. Open your original file, adjust according to your needs.

2. When ready, click File -> Save for Web and Devices

clip_image001

3. When that comes up, make sure the checkbox to convert to sRGB is checked and it is in the format you desire (small note: PNG files will not work properly in IE6).

SaveForSettings

4. Click Save!

You now have an image that will work properly!

A Simple Site Map

Similar to creating a menu – creating a site map is even easier, there are modules that can do this but with a little preparation it can be very easy to create yourself.

To start we are assuming every template used for the pages includes some ‘base template’ for common aspects for all pages.

To do this, create (or select if already created) the Base Template with the information you want to have and to that base template, add:

InSiteMap: Checkbox

Then create or modify the Page templates with the other information you want. From those templates, click to the Content tab, and select the Base template to be included:

sitecoretemplatecontent

In the Standard values for the base template, you may want to have InSiteMap checked so that it will be on by default for all the pages.

For the sitemap itself, we’re going to create a rendering and then we can place it wherever we would like.

The rendering creates a basic nested list of all the items that have InSiteMap checked.

<xsl:template match="*" mode="main">
<
ul>
<
li>
<
sc:link select="$home">
Home
</sc:link>
<
xsl:variable name="hasSubItems" select="$home/item[sc:fld('InSiteMap',.) = '1']"/>
<
xsl:if test="$hasSubItems">
<
xsl:call-template name="subitems">
<
xsl:with-param name="itemparent" select="$home" />
</
xsl:call-template>
</
xsl:if>

</
li>
</
ul>
</
xsl:template>

<
xsl:template name="subitems">
<
xsl:param name="itemparent" />
<
ul>
<
xsl:for-each select="$itemparent/item[sc:fld('InSiteMap',.) = '1']">
<
li>
<
sc:link>
<
sc:text field="Page Title" />
</
sc:link>
</
li>
<
xsl:variable name="hasSubItems" select="item[sc:fld('InSiteMap',.) = '1']"/>
<
xsl:if test="$hasSubItems">
<
xsl:call-template name="subitems">
<
xsl:with-param name="itemparent" select="." />
</
xsl:call-template>
</
xsl:if>
</
xsl:for-each>
</
ul>
</
xsl:template>

Above we list the link to the home item in an unordered list:

 <sc:link select="$home">
Home
</sc:link>

<sc:link> with no parameters will link to the current item that is being processed by the xslt file – if not specified by any settings this will default to the page that the rendering is on. Since the current page is Not actually the home page, we are choosing to use $home as the source for the link (if the source for the link was actually in a field in the item you’d used field=”field name”).


Moving on, if there are any items under home that are listed as ‘InSiteMap’ it will call our template named subitems and pass the value for the parent of the item.

        <xsl:variable  name="hasSubItems" select="$home/item[sc:fld('InSiteMap',.) = '1']"/>
<
xsl:if test="$hasSubItems">
<
xsl:call-template name="subitems">
<
xsl:with-param name="itemparent" select="$home" />
</
xsl:call-template>
</
xsl:if>

Here the variable hasSubItems is created and the value for this is determined by any items within $home containing the field InSiteMap being checked (=’1’ – unchecked would be =’0’).


If we have any items that will be in the sitemap under $home, we call our template.


Within the template, we create a new unordered list, and then go through each item which will be listed in the site map and display a link using the ‘Page Title’ (this is any field that we want to have displayed to represent the item). We then check to see if we have any subitems to display and run the template again! With a bit of recursion, we head through all the items on the site as long as they and their parents have InSiteMap checked.


All that is left is adding the rendering to a page to be seen, and it will display a nested list of the pages on the site to be styled as needed!


Alternately, instead of checking for a selected checkbox, it could run through all pages with a specific template(or selection of templates) if you did not need to worry about excluding any specific pages that are using it.

External and Internal Links as Items

I ran into a problem creating the navigation for the footer rendering on a page – On there I needed to have links to the following pages: terms, contact, careers, and the sitemap. The problem arose when trying to add ‘Contact’ and ‘Careers’: ‘Contact’ was a few levels down in the tree of content items and ‘Careers’ was an external page. Initially, I had a checkbox in the template of each page for if the item was in the footer (ie: InFooterNav checked) and then the XSLT file would go through the entire list of items to find what would be in the footer navigation. It wasn’t an ideal solution when so few items had the tag in the entire site and it did not help with my external link at all. Thus was born: The Link Template!

The new template basically consisted of:

Link Data:

  • Link: General Link //This is the link to our item or the URL for the external page
  • Nav Title: Single Line Text //The title we want to have displayed in our menu – this is the same as in my regular items
  • Target: Single Line Text (or a drop down list) //The target if we want to open the page in a new window – **this can be skipped since general link has this option 

Properties:

  • InFooterNav: Checkbox //Just a checkbox to see if this link is going to be in our footer, this is the same as regular items.

Within the Standard Values I assigned a new layout for the items with the following code within:

<% Sitecore.Data.Items.Item item = Sitecore.Context.Item; 
Response.Redirect(((Sitecore.Data.Fields.LinkField)item.Fields["Link"]).Url); %>

The above redirects the user to whatever URL was provided within the “Link” field.


I then created a bunch of items with the appropriate links in the folder where other footer only type items also lived – for our example let us say “/sitecore/content/Home/Footer/”


To retrieve my footer items I now only had to check that folder and not search the entire site to actually see if the box is checked.


And a little more useful - using this template, I could put a link to any external page under any item – allowing me to have external links within my navigation such as Careers.


The above layout will work fine for my footer, but what if you wanted links to open in other windows? Or didn’t want to take the extra step of creating a layout? The rendering can be changed to make use of our new template:

    <ul>
<
xsl:for-each select="$home/Footer/item[sc:fld('InFooterNav',.) = '1']">
<
li>
<
xsl:choose>
<
xsl:when test="@template = 'link template'">
<
xsl:variable name="linkTarget" select="sc:fld('Target',.)" />
<
sc:link field="Link" target="{$linkTarget}" >
<
sc:text field="Nav Title" />
</
sc:link>
</
xsl:when>
<
xsl:otherwise>
<
sc:link>
<
sc:text field="Nav Title" />
</
sc:link>
</
xsl:otherwise>
</
xsl:choose>
</
li>
</
xsl:for-each>
</
ul>


Above we have a choose statement to determine if this is using the new link template or not (called “Link Template” but listed in lowercase):

<xsl:when test="@template = 'link template'">

Then we create a variable for our target and create the link based on our General Link field called “Link” by specifying it for field:

<xsl:variable name="linkTarget" select="sc:fld('Target',.)" />
<
sc:link field="Link" target="{$linkTarget}" >
<
sc:text field="Nav Title" />
</
sc:link>

Otherwise if it is a normal item in the tree, we give it a normal link and continue to the next item!

<xsl:otherwise>
<
sc:link>
<
sc:text field="Nav Title" />
</
sc:link>
</
xsl:otherwise>

** General Links can specify the target for you so a lot of the above isn’t necessary as long as you’re using sc:link!

A Simple Single Level Menu with Rounded Edges

After taking some time to figure this out, I thought I’d share my approach to a simple single level menu rendering with rounded edges. Initially, the idea here is very straight forward – create a list, style it, voila! Unfortunately, Round edges and dynamic content make it a little less forgiving.

Here is an Example of what we are trying to achieve:

menubar

Each of these items would be a sub item in the site, all at the same level  under ‘/Sitecore/Content/Site’

In our XSLT  rendering we need to grab the list, and apply the appropriate styles to the appropriate items, notably: The first item needs to have a round corner on the left, the Last item needs to have a round corner on the right, and the inner items need to have borders around them all – and we need to be able to Hover for a different effect.

To do this I did the following:

<xsl:template match="*" mode="main">
<
ul id="MainNav">
<
xsl:for-each select="$SiteContent/item[sc:fld('InTopNav',.) = '1']">
<
xsl:variable name="EdgeClass">
<
xsl:if test="position()='1'">FirstItem</xsl:if>
<
xsl:if test="position() = last()">LastItem</xsl:if>
</
xsl:variable>
<
xsl:if test="position() = last()">
<
li class="preLastItem">
<
span>.</span>
</
li>
</
xsl:if>
<
li class="{$EdgeClass}" >
<
span>
<
sc:link >
<
sc:text field="Nav Title" />
</
sc:link>
</
span>
</
li>
</
xsl:for-each>
</
ul>
</xsl:template>

The above runs through every item which has InTopNav checked in that level (if you had /SiteCore/Content/Site/Home and then all the items under Home, it would be a bit different)


In terms of what happens when this runs:


1. First item is read and link displayed -- given the “FirstItem” class.


2. 2nd item is read -- link is displayed with No class assigned.



N. Last item is read: $EdgeClass is now “LastItem”, list item with a period is displayed followed by the list item for the last link -- given the “LastItem” class.


All that is left is styling the menu: I created extra wide images for the left rounded edge, right rounded edge and the general middle links so that they could overlap and slide around depending on the length of the text and set them as the background images for the links (ie: #Menu li.FirstItem a).

Web Forms for Marketers: Send Email

To have the save action for your form actually send email, you will need to change one of the settings, otherwise you will receive this error whenever submitting the form:

We experience a technical difficulty while processing your request. Your data may not have been correctly saved.

Also in your log (/data/logs/newest log file) you will see this error after the form has been submitted:

Exception: System.Net.WebException
Message: The remote name could not be resolved: 'example.host'
Source: System
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
WARN Web Forms for Marketers: an unhandled exception: Failure sending mail. has occured while trying to execute an action.

In your content tree, browse down to: /sitecore/system/Modules/Web Forms for Marketers/Settings/Actions/Save Actions/Send Mail


Under that item there will be a submit section with parameters:


wffmpara


Just replace example.host with your SMTP host information for the server, and form@example.host with the address you want to send mail from – save, and republish!


That should correct the error above and, barring any other issues, hopefully the form will be working as intended!

August 23, 2010

Hello World!

I’ve been itching to get this going for some time now, and decided to simply take the plunge!  I’ll be initially importing my previous posts from the Arke Systems Blog and then should have some more new tidbits shortly after.

I am somewhat new to the blogging world (and newly certified with Sitecore) and my hope is that this can eventually become a handy resource for others getting started with our favorite CMS! Initially there was a lot of struggle for me to find out basic information on how to do seemingly simple things (training really is the best way to go), so I’ll be posting a lot of small tips as I go along, and if I gloss over anything – comment!

One thing I'm really hoping for from this blog is some feedback – so please, comment and let me know where things can be improved or if this was useful at all – or if you’d like me to post about a particular topic.

Looking forward to the future!