Templates and Styles

People who have taken my classes know what a stickler I am for using templates and stylesheets. Of course you know what a template is, but what about a stylesheet? A stylesheet is simply the styles that you have defined as part of a file or template.

STYLES AND MORE STYLES

Let’s start from the beginning. In InDesign you have object styles, table styles, cell styles, paragraph styles, and character styles. With so many, it might seem as if creating styles for a document would be a lot of extra effort, So why bother? If you are doing a one-time, low-budget flier, creating styles may seem to be out of the question. After all, there may never be the occasion to do another similar document in the future. Maybe, but just maybe. You may have made it a habit to create document presets as part of creating a new document so you don’t have to set the many document preferences over again. The same reasoning can be applied to creating styles.

TEXT STYLES

When it comes to styling text, many users just go up to the Control panel, click on the “A” button to set all of the character attributes (font, font style, size, leading, kerning, tracking, and so on). They thenn click on the paragraph symbol to set all of the styling that has to do with paragraphs: alignment, indents, space above, space below, and so on. Depending on the number of ways text can be styled, this can add up to a lot of pointing and clicking.

Wouldn’t it be a lot easier to just grab a paragraph style and maybe change just one or two of its properties? Of course. But to create all those styles? Are you kidding?

START WITH DEFAULT STYLES

Believe me, it’s not that big of a deal. In just a few minutes you can set up default styles that will get your text styling started with each new document. Start with [Basic Paragraph]. It comes with InDesign by default and can be found in InDesign’s Paragraph Styles panel (Window > Styles > Paragraph Styles or Command/Control F11). With no documents open, you can change this style to the styling you will use most often. Here’s how:

  1. With InDesign running in the foreground, open the Paragraph Styles panel (Window > Styles > Paragraph Styles).
  2. Double-click on the entry for [Basic Paragraph]. This opens the Paragraph Style Options dialog.
  3. In the dialog that opens, notice that you can’t change the name for the default style.
  4. Change the font, font style, size, and leading. Set the values for these properties to match those that you use most for body text. (Keep your settings very generic.)
  5. Click OK when you are done.

While you are at it, you may want to set up a style for the most used sans-serif headline that you use. Provide settings for font, font style, and size most used (maybe this is Myriad Pro, Bold, 24 pt). Name the style “Basic Sans.”

Do the same for your most used serif headlines. This may be the same font you used for your [Basic Paragraph] style. If so you may want to set its Based On property to [Basic Paragraph].

Not done yet. Switch to the Character Style panel. Set a style for “Bold.” Its based on style will be [None] and the ONLY setting you will assign to this style is Font Style (in the Basic Character Formats panel). Choose Bold from the Font Style dropdown. That’s it. Do the same for a style named “Italic”, with the Font Style set to (you guessed it) Italic. Lastly, set one for BoldItalic.

Now, at least you have a few styles that will be at your disposal with every new document you create.

If the only documents you will ever create is a weekly newsletter that never changes its fonts and styling, you could also set the styles for the newsletter at the application (default) level. But I would not suggest it. Leave the rest of your style definitions for your templates.

TEMPLATES

Chances are that there is already a template set up for your weekly newsletter. But, just for kicks and giggles, assume that you now need to create a template for your newsletter. Hopefully, the styles for this document can be based on the styles you created at the application level. If not, you can override the settings for all at the document level. This does not change the settings for the styles you set at the application level. Your default styles are still in tact and will be ready for you to use in each new document you create.

When you need to create a headline for your newsletter, you may want to base it on one of your default styles. If so, click on the default style to style the text. You then alter the styling (size, leading, and justification) using the widgets in the Control panel. With the styled headline still selected, go to the Paragraph Styles panel. Click New Paragraph Style from its context style menu (flyout menu). This opens the New Paragraph Style dialog. In the General tab for the dialog give the style a name (“Head_24” or whatever is appropriate). Be sure that Based On is set to the appropriate paragraph style. This will be [Basic Paragraph] or one of the other styles you set at the application level.

The settings in the Basic Character Formats tab for the dialog will be as established for the text selected in the document. You may also want to establish settings for other settings you may have overlooked. Additionally, you may want to visit other tabs in the dialog for setting indents and spacing, tabs, keep options, hyphenation, Span Columns, and so on. Click OK to save your settings. Before you leave the Paragraph Style panel, be sure to click on the new style you just created to style your headline.

Continue to do this for each styling as you style text in your newsletter.

When your newsletter is approved for publication, do one more thing: save the document as a template. Before you transfer the template to a protected folder on your computer, you may want to embed any assets that will be used consistently in the publication. Alternatively, you can place these assets in a library. All other linked assets will need to be removed. (You don’t want missing assets to come up each time you go to use your template.) You will also want to remove any text that will not be used in future documents.

WHERE TO PLACE THE TEMPLATE

If you have administrative privileges, you may want to store your templates in the Application folder for Adobe InDesign. Name the folder “Templates” and drag your revised template into the folder. Without administrative privileges, you wil need to find a protected folder somewhere on your computer (perhaps in your Library folder). The next time you need to create your newsletter, you may want to use a script to make the process of crating a document from the template that much easier.

Document from Template Script – AppleScript

   set templateName to "MyNewsletter.indt"
   set parentPath to path to documents folder from user domain as string
   set saveName to "MyNewsletter.indd"
   set savePath to parentPath & saveName
   tell application "Adobe InDesign CC 2015"
	set appPath to file path as string
	set folderPath to appPath & "Templates"
	try
	   set templatePath to (folderPath & ":" & templateName) as alias
	   set docRef to open templatePath
	on error
	   activate
	   display alert "template " & templateName & " not found"
	   return
	end try
	save docRef to savePath
   end tell

Document from Template Script – ExtendScript

   //name of template to use
   var templateName = "MyPublication.indt";
   //path and name for saving document
   var parentPath = Folder.myDocuments;
   var saveName = "myPublication.indd";
   var savePath = parentPath + "/" + saveName;
   //get path to application folder
   var appPath = app.filePath.absoluteURI;
   var folderPath = appPath + "/Templates";
   //if file exists, open it to create new document
    try {
        var templatePath = File(folderPath + "/" + templateName);
        if (File(templatePath).exists){
           var docRef = app.open(templatePath);
         } else {
             throw ("template " + templatePath + " not found");
          }
          docRef.save (new File(savePath)); 
     } catch (e) {
         alert (e);
     }

Notice that the script not only creates a new document from the template, but it also saves the document to a specified folder with a specified name (savePath). This can be just the beginning of a script that could also do one or more of the following:

  • add a date stamp to the file name (MyNewsletter102715.indd)
  • add metadata to the file for easy search in the future
  • update the date for the running header/footer in the document (text variable)
  • so much more that your imagination can come up with

NO STYLES? WHAT THEN?

So now the company you work for has seen that you are so efficient in creating the newsletter, they want you to set up some product pages. You decide that you like the look and feel of the paragraph styles you used for the newsletter. So once you create the structure for your product page document, you will want to import the styles from your newsletter template (or maybe from another template that you have created). Below is a little script that will let you choose the template you want to get the text styles from. Once chosen, the script imports the text styles from the template.

Import Styles (AppleScript)

   (*assumes document is open and no modal dialogs are open*)
   tell application "Adobe InDesign CC 2015"
	set docRef to document 1
	set appPath to file path as string
	set folderPath to appPath & "Templates"
	set templateList to list folder folderPath without invisibles
	set templateChoice to choose from list templateList without multiple selections allowed
	if templateChoice is not false then
	   set fileRef to (folderPath & ":" & item 1 of templateChoice) as alias
	end if
	tell document 1
	   import styles format text styles format from fileRef
	end tell
end tell 

Import Styles (ExtendScript)

   //assumes target document is document 1
   var docRef = app.documents.item(0);
   var appPath = app.filePath.absoluteURI;
   var folderPath = appPath + "/Templates";
   var fileNames = listFiles(folderPath);
   try {
      var fileChoice = userDialog (fileNames);
      var fileRef = File(folderPath + "/" + fileChoice);
      //by default, globalClashResolutionStrategy is LOAD_ALL_WITH_OVERWRITE
      docRef.importStyles (ImportFormat.TEXT_STYLES_FORMAT, fileRef, GlobalClashResolutionStrategy.LOAD_ALL_WITH_OVERWRITE);
   } catch (e) {
      alert (e);
   }
   //returns list of file names for files in folderPath
   function listFiles (folderPath) {
     var folderObj = Folder(folderPath);
     var fileList = folderObj.getFiles(); //"*" is default
     var fileNames = [];
     for (var i = 0; i < fileList.length; i++) {
        var fName = File(fileList[i]).name;
        if (fName.substr(0, 1)!=".") {
          fileNames.push(fName);
        }
     }
     return (fileNames);
   }
   //dialog allows user to choose file from list of file names
   function userDialog (fileNames) {
      var userCancelled = false;
      var oldPref = app.scriptPreferences.userInteractionLevel;
      app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
      var dlgRef = app.dialogs.add({name:"Choose File", canCancel:true, label:"User Dialog"});
      with (dlgRef.dialogColumns.add()) {
         with (dialogRows.add()) {
            staticTexts.add({staticLabel:"Choose a file:"});
            var fileDropdown = dropdowns.add({minWidth:240, stringList:fileNames, selectedIndex:0});
         }
     }
     if (dlgRef.show() == true){
        var fileChoice = fileNames[fileDropdown.selectedIndex];
     } else {
        userCancelled = true;
     }
     //destroy the dialog
     dlgRef.destroy();
     //set script preferences back to prior setting
     app.scriptPreferences.userInteractionLevel = oldPref;
     //throw error if user cancelled
     if (userCancelled){
        throw ("User Cancelled");
     } else {
        return (fileChoice);
     }
   } //end function 

Comparing the script for AppleScript against the one for ExtendScript, one can easily see why I prefer using AppleScript for demonstration scripts. The problem is that ExtendScript (JavaScript) is cross platform so cannot take advantage of some of the nice scripting methods available in AppleScript. But, if you are using a Windows machine, ExtendScript is for you. Or, maybe you would prefer using Visual Basic. (Sorry, I haven’t supported that language since 2010).

ONWARD AND UPWARD

Once you have a number of templates saved with text styles you are sure to have many opportunities to take advantage having this treasure trove at your disposal.

But this is just the beginning. You can save text styles so that they are part of object styles. With this, when you create a text frame, you can select an object style and have the text in the frame styled using the styles for the object style.

Ah, but it gets better. You can match your text styles to styles in a cascading style sheet (css) and export your documents to web with your styles in tact.

So keep tuned, we will be exploring these options in upcoming posts.

Disclaimer

Scripts provided in blog posts are for demonstration purposes. For this reason, the scripts are pared down to their basic essentials. Readers are advised to use the scripts as a guide for creating their own scripts with the knowledge that their scripts will require additional error handling to make sure the scripts will not fault under production use.