Jump to content

Javascript Rule to show text fields based on graphic


ChasePI

Recommended Posts

I'm new to Fusion Pro and Javascript and I'm trying to setup a rule. I'm working on a banner that we print that has 2 different backgrounds they can choose from. When the designer set this up a few years ago they didn't take into consideration that the imprint area is not in the same position for each background option.

 

The rule I'm trying to create is to show and hide text depending on the background image they select. I also need to take in to consideration that if they include 2 phone numbers it adds a bullet in between.

 

My current rule works for the bullet issue but it shows both frames on my template in the PDF. I also don't know if it is going to work online either since they will be picking an image out of a gallery not plugging it into a field.

 

 
if ((Field("Layout") == "Blue_Background.pdf") && (Field("Info Line 2").indexOf("1") > -1))
{
  return "<span>" + TaggedDataField("Info Line 1") + RawText(" • ") + TaggedDataField("Info Line 2") + "</span>";
}
else
{
  return "<span>" + TaggedDataField("Info Line 1") + "</span>";
}

return ""; 

Any suggestions would be great, if I left any important information out please let me know.

 

Thanks

Link to comment
Share on other sites

How about creating a rule for "building" your text (with tagged text checked) and applying the rule to both background's frames:

var myText = Field("Info Line 1");
if (Field("Info Line 2") != "") myText += " • " + Field("Info Line 2");
return myText;

Then, in an OnRecordStart callback rule, you would include the following code to suppress the "unused" frame:

if (Field("Layout") == "Blue_background.pdf") FindTextFrame("[i]yourNONblueFrameName[/i]").suppress = true;
else FindTextFrame("[i]yourBlueFrameName[/i]").suppress = true;

Link to comment
Share on other sites

I plugged in the code to suppress the "unused" frame:

 

if (Field("Layout") == "Blue_background.pdf") FindTextFrame("Dog_Info").suppress = true;
else FindTextFrame("Blue_Info").suppress = true;

 

but it suppress the "Blue_Info" frame each time no matter what layout is picked. If I reverse it and and start with Dog_Background it suppress the "Dog_Info" frame each time.

Link to comment
Share on other sites

The template is setup to be a one page document that has 1 graphic frame pulling in the correct image based on the data field layout. I have triple checked the data and everything is correct.

 

I was able to create a rule to pull in the "Company Name" field into the correct frame but had to essiential create the same rule twice and just put it in each frame. I could do the same for the "Info Line" rules I'm working on now but it wouldn't matter. Once I get it loaded to the MarcomCentral store it doesn't work. I guess because they are pulling the image out of a gallery and not plugging in text in the "Layout" field.

 

I may scrap this template and start fresh and go at it a different way.

 

Thanks for your help.

Link to comment
Share on other sites

Once I get it loaded to the MarcomCentral store it doesn't work. I guess because they are pulling the image out of a gallery and not plugging in text in the "Layout" field.

First of all, if you're having a problem specific to MarcomCentral, please post your question in the MarcomCentral forum.

 

That said, I can tell you that when you have a graphic field, it is presented to the composition differently by MarcomCentral than it is by your data file in FusionPro Desktop. Specifically, MarcomCentral uses a full UNC path to a graphic in its image library. So you need to change this:

if ((Field("Layout") == "Blue_Background.pdf"))

to this:

if (ToLower(GetFileName(Field("Layout"))) == "blue_background.pdf")

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...