photools.com Community

IMatch Discussion Boards => General Discussion and Questions => Topic started by: sinus on June 08, 2015, 06:34:40 PM

Title: Formating variables with a file
Post by: sinus on June 08, 2015, 06:34:40 PM
Hi Mario

I have now searched about one hour without success.
I know, you have once wrote in a side-note (but with an example), that we can load in a variables a file instead only simply display a text.

This means, for example in this variables (from the helpfile):

{File.Name|strcomp:Beach,less,equal,greater}
(Compares the variable value to 'Beach' and returns 'less, 'equal' or 'greater', depending on the outcome.)

we could let display a file (an png-icon for example) instead of let display the words "less", "equal" or "greater".

I know for sure, that you wrote this in the forum here, but cannot find it, whatever I search for.  :-[ :-\

Can you remember maybe the correct variable-code for this?

Title: Re: Formating variables with a file
Post by: Mario on June 08, 2015, 07:38:03 PM
That's tricky. Because most variables escape unsafe text (e.g. < and >) to prevent invalid markup. But the following statement uses pereplace to overcome this (see the help for details).

{File.Ext|contains:NEF,y,n,false;pereplace:y==<Image Source='file://c:\images\banana.png'/>}

If the file extension contains NEF, the first function returns y else n.
The prereplace then replaces y with an <Image> XAML tag that loads a PNG file from the local disk.
This prevents the variable parser from escaping < and > and thus we produce real markup.

The result: A bunch of bananas is displayed in the footer of each NEF file:

(https://www.photools.com/community/index.php?action=dlattach;topic=4621.0;attach=10144;image)

[attachment deleted by admin]
Title: Re: Formating variables with a file
Post by: sinus on June 08, 2015, 07:46:24 PM
Phew, simply fantastic!!!!

Such a quick answer and such a good answer and such a funny answer (the bananas looks funny  ;D).

Thanks a lot, Mario, I will do so, very cool!

And yes: it works!
Title: Re: Formating variables with a file
Post by: sinus on June 09, 2015, 08:55:14 AM
Only to report this:

The variable in Mario's example above works perfectly in the Windows Layout.
In my html-template for an App the line works with this:

<p>{File.Ext|contains:NEF,y,n,false;pereplace:y==<Image src="file://c:\sinus-icons\loc2.png"/>}</p>

See my attachement, the star is the png.

[attachment deleted by admin]