CodeRush Templates – Creation Basics

Even the simplest of CodeRush Templates (one without any TextCommands or StringProviders) can be really useful. Such a template expands exactly the same every time it’s used.

In this post we’re going to create one such simple template.

Our scenario is one in which you are building a web page and you’d like to quickly generate some simple but authentic looking text to flesh the page out with.

This scenario is typically dealt with using lorem ipsum text. This text is typically generated by a computer to the specification of a user. It has similar flow to most Latin based languages and makes for realistic looking content, when mocking out a page.

We’re going to make a template which delivers the same paragraph of Lorem Ipsum each time it’s invoked. You’ll be able to type “lorem<space>” and have it expand to the pre-calculated piece of text.

So let’s not hold back any more… let’s get on with it.

Which language?

  • Open up the Templates options page and change the language dropdown to HTML (Details here).

We’re doing this because it’s rarely useful to inject quantities of “lorem Ipsum” text into VB or C# code. Instead we restrict the template to only expand into files understood to contain html.

Create a Custom folder

  • Right click in the template tree and choose “New Root Category”
  • Name the Folder “Custom”

TemplateTreeContextMenuWe always recommend creating your new templates within a top-level folder of your own (typically called ‘Custom’). The main reason for doing this is for organisational purposes. By placing your templates under a single top level folder, you can export them as a group.

This can ease processes like backing up or sharing the templates and it’s why, in my screencasts, you’ll often see a Custom folder in my templates tree that does not ship with CodeRush.

Create a new blank template

  • Right click the “Custom” folder and choose “New Template” (you can also use the NewTemplateIcon icon above the template tree.)
  • Type “lorem” (without the quotes") and hit ok

NewTemplateLorem

Add the detail

As with all pure literal templates, the expansion for this one is very simple indeed. I generated the following paragraph of lorem ipsum text using http://www.lipsum.com/

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas blandit sapien sed metus porttitor convallis. Aenean eget tortor arcu, sollicitudin tincidunt lectus. Donec eget justo lorem, ut tempor nulla. Nulla facilisi. Nulla a urna sed nulla ultricies sollicitudin vitae a lacus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi turpis nunc, hendrerit at pretium nec, vulputate nec velit. Nullam facilisis, erat scelerisque fermentum consequat, lectus dui pretium sem, a hendrerit massa erat eu mi. Integer dignissim est eget libero auctor accumsan.’

Copy this text to the clipboard and paste it into the expansion box

ExpansionLorum

You should now have…

  • a folder called ‘Custom’
  • a new template called ‘lorem’ who’s expansion contains some lorem ipsum text.

That’s about all there is to it.  Hit the ok button and let’s test it…

Open or create a new html page, locate a reasonable spot and type ‘lorem<space>’

You should find that CodeRush immediately fills the space your caret was located, with a single paragraph of lorem ipsum text.

Typically you’d create the basic structure of your web page. (Typically DIV tags with CSS, although there are some who still use tables.) Once this basic structure is laid out, you can fill each piece with some lorem ipsum and this will make your structure seem that much firmer/

I’ll be the first to admit that this template isn’t the most awe-inspiring thing in the world, but it could definitely save you a whole bunch of typing or failing that, it would at least save you from navigating to a lorem ipsum generator and then cutting and pasting back to your html file.

Next time we’ll show you how to use some StringProviders and TextCommands

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.