Jump to content

Return an Image value Based on the Value of a Selected Image?


DWilliams

Recommended Posts

Hello Again,

 

I find myself having trouble with some code that I have validated in Fusion Pro VDP's code editor, and as data output on my local computer, not behaving as expected in Marcom.

 

The idea is that a user will select a cover image for a multiple page brochure - out of a gallery style picker - and depending on the specific image they select the background images of the inside pages, inset flap and back cover will populate with images that best compliment the colors in the cover image. Basically letting the user pick the cover and having that determines the style for every other background image in the booklet.

 

My variable to select the cover is applied directly to the graphic frame of the cover, and is functioning correctly in Marcom, but the value of it does not seem to be making it to the rule in the template. The following code is an example of the rule I wrote for the back cover.

 

switch (GetFileName(Field("Cover Image")).toLowerCase())
{
case "Sunset_Fade.pdf".toLowerCase():
	return Resource("Backer_Red.pdf");
 case "Waterfall.pdf".toLowerCase():
	return Resource("Backer_Blue.pdf");
 case "Starry_Sky.pdf".toLowerCase():
	return Resource("Backer_Purple.pdf");
default:
	return Resource("Backer_Gray.pdf");
}

 

The rule is structured as a graphic switch rule, that I converted to java to try to trouble shoot, but in Marcom it only returns the default value.

 

 

I got it to work based on a text value input from Marcom, using a different variable as a quick test, but the client wants to be able to see the cover images in a gallery when ordering the brochure, so I cannot alter that part on the product. I'm baffled as to why it doesn't work.

 

Any thoughts on how to accomplish this while in Marcom?

 

Help is much appreciated!

Link to comment
Share on other sites

First, if the question really is specific to MarcomCentral, then it should be asked in the MarcomCentral forum.

 

That said, it seems that the data field value from the data file that MarcomCentral is generating for the end user's web form selections is different than what you're expecting.

 

I would think that the easiest way to troubleshoot this would be to simply set the value of that "Cover Image" data field in a text frame, then you should see it right there in the output. My guess is that the data field value that MarcomCentral is putting in there isn't just a file path, it's a graphic tag.

Link to comment
Share on other sites

Your problem sounds pretty similar to this thread. I'd bet with a few tweaks, the same solution would work for you:


var header = String(GetFileName(Field("Cover Image")).match(/(sunset_fade|waterfall|starry_sky)\.pdf/ig));
var color = '';

switch (ToLower(header)){
   case "sunset_fade.pdf":
       color = "Red";
       break;
    case "waterfall.pdf":
       color = "Blue";
       break;
    case "starry_sky.pdf":
       color = "Purple";
       break;
   default:
       color = "Gray";
}

return Resource("Backer_" + color + ".pdf");

Link to comment
Share on other sites

Your problem sounds pretty similar to this thread. I'd bet with a few tweaks, the same solution would work for you:


var header = String(GetFileName(Field("Cover Image")).match(/(sunset_fade|waterfall|starry_sky)\.pdf/ig));
var color = '';

switch (ToLower(header)){
   case "sunset_fade.pdf":
       color = "Red";
       break;
    case "waterfall.pdf":
       color = "Blue";
       break;
    case "starry_sky.pdf":
       color = "Purple";
       break;
   default:
       color = "Gray";
}

return Resource("Backer_" + color + ".pdf");

 

Thank you both so much, this answer worked!

 

Logically, I can't see how the resource return being outside the switch rule should have an effect on the return value other than being able to build the file name returned from a variable? I think what I needed was the line ensuring the input matched my options while converting the input value to a string before heading into the switch. I haven't tested the theory yet, but I might when I'm less pressed for time.

 

This also marks the first coding use I have had for a regular expression outside of an academic setting. Yay..?

 

:cool:

Link to comment
Share on other sites

Logically, I can't see how the resource return being outside the switch rule should have an effect on the return value other than being able to build the file name returned from a variable?

There shouldn't be. That's just personal preference for me. I'm not a fan of writing the same things multiple times.

I think what I needed was the line ensuring the input matched my options while converting the input value to a string before heading into the switch.

I don't think that's it. The "String" function is converting the array value that's returned from the 'match' method to a string – not your input value. Your input value is already a string. What you were probably missing was the RegExp that is searching the entire field for "sunset_fade.pdf" (for example) so that if what Dan said is true and MarcomCentral is tagging that field, a match is still made.

 

So, if your field value in Producer is "/path/to/sunset_fade.pdf" then:

GetFileName("/path/to/sunset_fade.pdf") == "sunset_fade.pdf"

But MarcomCentral may tag it so:

GetFileName('<graphic file="/path/to/sunset_fade.pdf">') == 'sunset_fade.pdf[color="Red"]">[/color]' // [color="red"]NOT "sunset_fade.pdf"[/color]

But with the RegExp the match is still made:

String(GetFileName('<graphic file="/path/to/sunset_fade.pdf">).match(/(sunset_fade|waterfall|starry_sky)\.pdf/ig)) == "sunset_fade.pdf"

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...