Jump to content

Text Resources based on Image


Recommended Posts

Hopefully someone can give me a little advice again.

 

I'm creating a template for a postcard and I would like the message on the back to be different depending on the front image. I have 3 different options for the front and 3 formatted text resources set. I have created a simple switch rule to pull the correct text resource based on the front image.

 

switch (Field("FrontImage - Spring").toLowerCase())
{
   case "Dog_Sweater.jpg".toLowerCase():
       return Resource("Dog_Sweater");
   case "Dumb_Ideas.jpg".toLowerCase():
       return Resource("Dumb_Ideas");
   case "Peace_Quiet.jpg".toLowerCase():
       return Resource("Peace_Quiet");
   default:
       return "";
}

Once the template is online the user selects the front image from the gallery but nothing shows on the back for my text resources.

 

Any help would be great, I'm stumped again.

 

Thanks,

Chase

Link to comment
Share on other sites

Add .content to the end of your resource names.

 

ie return Resource("Dog_Sweater").content;

 

Edit: I just tried this and it works fine with or without the .content although you can see it validating better with it added. Try putting a value in the Default and see if that works, if it does then it's simply a matter of naming conventions, in which case you might want to clean out the .toLowerCase() as they aren't really needed.

Link to comment
Share on other sites

Thomas,

 

I tired to adjust the rule with and without the .content and removed the .toLowerCase() and it still works great with the Fusion Pro desktop but not functioning once i upload it to the site.

 

I have attached a PDF of the screens from the websites, would it have to do with any of those settings?

 

switch (Field("FrontImage"))
{
   case "Dog_Sweater":
       return Resource("Dog_Sweater");
   case "Dumb_Ideas":
       return Resource("Dumb_Ideas");
   case "Peace_Quiet":
       return Resource("Peace_Quiet");
   default:
       return "";
}

Image_Txt_Resources.pdf

Link to comment
Share on other sites

The field values in Marcom are the image UUIDs. They used to have the name of the image appended to them so the following code worked. This recently changed and I haven't tested this but it might work, give it a shot.

 

var myfield = Field("FrontImage");

if (myfield.indexOf("Dog_Sweater") != -1)

return "Dog_Sweater";

else if (myfield.indexOf("Dumb_Ideas") != -1)

return "Dumb_Ideas";

else if (myfield.indexOf("Peace_Quiet") != -1)

return "Peace_Quiet";

else

return "";

 

Basically you are finding the position of the string within the entire value selected (-1 being not found). This gets around not knowing what the UUID is.

Link to comment
Share on other sites

That worked with the following code edits...

 

var myfield = Field("FrontImage");
if (myfield.indexOf("Dog_Sweater") != -1)
return Resource ("Dog_Sweater");
else if (myfield.indexOf("Dumb_Ideas") != -1)
return Resource ("Dumb_Ideas");
else if (myfield.indexOf("Peace_Quiet") != -1)
return Resource ("Peace_Quiet");
else
return "";

 

Thanks for your help with this.

Link to comment
Share on other sites

Hi there, once an image is uploaded to an image library, the value in a graphic field is no longer just the image name itself (such as "DOG.pdf"), it will is the entire PATH to the image (such as "\\server\folders\12345\BackgroundColor\images\src\DOG.pdf"). So if a switch rule is going to return something when "DOG.pdf" is selected, the rule will not return anything because the library path does not match "DOG.pdf."

 

There is a function in FP called GetFileName() which strips the path out of the image name so that you can still use it in a switch rule. The correct usage of this function would be this:

 

if (GetFileName(Field("FrontImage")) == "Dog_Sweater.jpg")

return Resource("Dog_Sweater"); ...

Link to comment
Share on other sites

As stella notes, if you only want the file name, then you should use the GetFileName function, like so:

switch (GetFileName(Field("FrontImage - Spring")).toLowerCase())
{
   case "Dog_Sweater.jpg".toLowerCase():
       return Resource("Dog_Sweater");
   case "Dumb_Ideas.jpg".toLowerCase():
       return Resource("Dumb_Ideas");
   case "Peace_Quiet.jpg".toLowerCase():
       return Resource("Peace_Quiet");
   default:
       return "";
}}

Note that the above is exactly what a Switch Wizard rule generates if you set the "Compare As" type to "File Name" and convert the rule to JavaScript. This will work the same way in MarcomCentral as it does in FP Desktop, as long as the file names are the same.

 

The rule above could be further reduced to this:

return Resource(GetFileName(Field("FrontImage - Spring")).replace(/\.\w+$/, ''));

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...