Jump to content

Ampersand converting to html through MarcomCentral


KristenBalla

Recommended Posts

I have a title field that needs to be all caps and allow special characters like the ampersand. I've tried a couple different rules....

 

I used the standard case selection rule while UNchecking "Treat returned strings as tagged text"

 

and I tried this rule with the "treat returned strings as tagged text" checked:

return '<uppercase>' + NormalizeEntities (Field("Title")) + '</uppercase>';Field("Title")

 

The last one appeared to work when I composed the piece on my desk top, but both ways I get "&AMP; AMP;" when I type and ampersand in the online template. Can someone tell me what I'm doing wrong.

 

thanks!

Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...

I'm fighting with the same problem - in addition to having ampersand as is I need to add large space (larger then regular - kind of em-space) around ampersand...

 

So either ampersand disappered, or spaces...

 

Any help?

Edited by MikeVM
Link to comment
Share on other sites

Replace instances of Field in your rules with TaggedDataField, and remove the calls to NormalizeEntities. Leave the "Treat returned strings as tagged text" box checked (on).

 

Note that this is a new feature in FusionPro 7.1, and is supported on MarcomCentral.

Link to comment
Share on other sites

  • 1 year later...
The issue I am having is that I am returning a case selection rule not a field so I'm not sure where I am supposed to be replacing the TaggedDataField function instead of Field. I am using your prebuilt rules for the case selection not straight javascript since I am not that fluent.
Link to comment
Share on other sites

  • 3 years later...
Dan I am having the same issue as Modern Postcard above, can you please address that scenario. thanks.

If you mean you're using the XML Template rule named "Case selection for a name field Rule", then you need to first convert the rule to JavaScript, then replace every instance of "Field" with "TaggedDataField". (You can use the "Find..." button in the Rule Editor to do a "Replace All".) The result should look like this:

var Var1 = "Name"; // or whatever field you chose
var CaseSelection = "propercase"; // or whatever case/mode you chose

if(CaseSelection == "allcaps")
return ToUpper(TaggedDataField(Var1));

if(CaseSelection == "smallcaps")
return "<smallcap>" + TaggedDataField(Var1) + "</smallcap>";

if(CaseSelection == "propercase")
return ToTitleCase(TaggedDataField(Var1));

if(CaseSelection == "lowercase")
return ToLower(TaggedDataField(Var1));

However, the caveat here is that the "propercase" mode may not work exactly right, as the ToTitleCase function doesn't account for tagged markup. (And it's not really right for all names anyway.)

Link to comment
Share on other sites

  • 4 months later...

Is this (Dan's last reply) still valid? I've changed my entries to match, and I'm returning the same error.

 

The only other aspect of the template that I'm curious about, is that it's in a formatted text resource.

 

Here's my converted javascript rule;

 

var Var1 = "Title";

var CaseSelection = "allcaps";

 

 

 

if(CaseSelection == "allcaps")

return ToUpper(TaggedDataField(Var1));

 

if(CaseSelection == "smallcaps")

return "<smallcap>" + TaggedDataField(Var1) + "</smallcap>";

 

if(CaseSelection == "propercase")

return ToTitleCase(TaggedDataField(Var1));

 

if(CaseSelection == "lowercase")

return ToLower(TaggedDataField(Var1));

 

For now, I've disabled the function and asked the client to enter UPPER. I'd prefer to automate the solution.

 

Many thanks.

Link to comment
Share on other sites

Is this (Dan's last reply) still valid? I've changed my entries to match, and I'm returning the same error.

Nothing has changed about how tagged markup is handled. Every job is different, though.

The only other aspect of the template that I'm curious about, is that it's in a formatted text resource.

What do you mean "it's in a formatted text resource?" What exactly is "in" the resource? Do you mean that you're calling out the rule from a formatted text resource? If so, then you probably are re-encoding the tagged markup in another rule that's returning the resource. What happens if you call out the rule you posted directly in a text frame instead?

Here's my converted javascript rule;

var Var1 = "Title";
var CaseSelection = "allcaps";

if(CaseSelection == "allcaps")
return ToUpper(TaggedDataField(Var1));

// Some other code that will never be reached below...

If you only want uppercase text, you can just do this:

return ToUpper(Field("Title"));

And you do NOT need to check the "Treat returned strings as tagged text" box. (Although there's a small chance that existing tags and entities in the tagged markup data generated by MarcomCentral may not work properly when converted to uppercase.)

Link to comment
Share on other sites

  • 1 year later...

Not sure why, but this seems to have stopped working for me:

 

//My Field Title2 = Title & 2

return ToUpper(TaggedDataField("Title2"));

//Rule Editor Validation Returns: TITLE &AMP; 2
//MarcomCentral Returns: TITLE 2
//It drops the ampersand.

 

I tried replacing the above with this in MarcomCentral if the data might use an ampersand:

 

var str = Field("Title2");//My Field Title2 = Title & 2
var res = str.toUpperCase();

return (res).replace(/&AMP;/gi, "&");

//Rule Editor Validation Returns: TITLE & 2
//MarcomCentral Returns: TITLE & 2
//It no longer drops the ampersand.

 

Any idea why TaggedDataField stopped working in my rules?

Edited by David Miller
Link to comment
Share on other sites

Any idea why TaggedDataField stopped working in my rules?

TaggedDataField hasn't stopped working. It's returning the string with the ampersand converted to an entity, exactly as it's supposed to do, and as it has always done. Then you're converting that entity to all-caps. This will give you exactly the same results:

//My Field Title2 = Title & 2
var res = ToUpper(TaggedDataField("Title2"));
return (res).replace(/&AMP;/gi, "&");

If anything has changed, it's how the upper-cased &AMP; entity is being handled by FusionPro's tagged markup parser. But that's not really a valid entity.

 

Your example may be purposefully trivial, but I think the correct way to do what you want is to uncheck the "Treat returned strings as tagged" box and do this:

return ToUpper(UntaggedDataField("Title2"));

Link to comment
Share on other sites

×
×
  • Create New...