Formating variables with a file

Started by sinus, June 08, 2015, 06:34:40 PM

Previous topic - Next topic

sinus

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?

Best wishes from Switzerland! :-)
Markus

Mario

#1
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:



[attachment deleted by admin]
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

sinus

#2
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!
Best wishes from Switzerland! :-)
Markus

sinus

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]
Best wishes from Switzerland! :-)
Markus