Jump to content

Font option in a data field


Kal

Recommended Posts

Here's some code that searches for an area code pattern that matches what you've described (3 numbers within parentheses) and changes the font using span tags:

var default_font = "Times";
var areaCode_font = "Arial";
var phone = "(411)123-4567";

return '<span font="' + default_font + '">' + phone.replace(/(\(\d{3}\))/,'<span font="' + areaCode_font + '">$1</span>') + '</span>';

Link to comment
Share on other sites

Thanks Ste but what I want to do is add FusionPro codes in the Flat Data file before it hits FusionPro.

 

Flat Data file:

(416) 111-4567

(416) 122-5678

(416) 133-6789

 

(416) will be tagged as Times font and the rest will be tagged as Arial font, all this in the Flat data file. Can this be done?

 

Hope this is clear

 

Thanks

Link to comment
Share on other sites

Thanks Ste but what I want to do is add FusionPro codes in the Flat Data file before it hits FusionPro.

 

Flat Data file:

(416) 111-4567

(416) 122-5678

(416) 133-6789

 

(416) will be tagged as Times font and the rest will be tagged as Arial font, all this in the Flat data file. Can this be done?

Yes, you can use markup tags in the data file, as long as you check the "Treat field values as tagged text" box on the "Data Fields - Flat File" step of the Define Data Source Wizard. You could include tagging like so right in the data:

<f name="Times">(416) </f>111-4567

or:

<span font="Times">(416) </span>111-4567

or:

<f name="Times">(416) <f name="Arial">111-4567

etc.

 

Or, instead of a flat file, you can use Tagged Markup input data, which is basically an XML file with <record> and <story> tags for your data fields.

 

However, there's a very big caveat with either of these, which is that ALL the data will be treated as tagged markup, so you have to be careful if your data contains characters such as ampersands, quotes, and less-than symbols which could be mistaken for tags instead of literal text, and replace these in the data file with entities such as "&". It's also tricky to make sure that space characters are handled properly. Frankly, there are a lot of pitfalls here, many of which are not obvious. So, even though it's possible to use tags in your data, I strongly recommend that you not do that.

 

A much better way to handle something like this is with a rule, which will apply the formatting you want to the data. In your case, you could create a rule like step's, or like this:

return Field("phone").replace(/^(\(\d{3}\)\s*)/, '<f name="Arial">$1</f>');

This will allow you to control the formatting in the variable data template, and to use different formatting in different templates (or even in different places in the same template), without modifying the data. This is a pretty basic "best practice" for VDP jobs: data is data, and formatting is formatting.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...