Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > custom macro parameters View modes: 
User avatar
Member
Member
celeste - 10/20/2011 1:39:14 PM
   
custom macro parameters
Hi,

I have a need to rewrite URLs (javascript, images, etc) in my layouts to a different format in some circumstances. ex:
original: http://www.mysite.com/images/blue.gif
new: http://www.myNewSite.com/newimages/blue.gif

I have coded a method that can do this. How do I invoke this method from my layouts? I tried a custom macro, but I cannot understand how to pass in the URL to change.

Using 5.5R2

{% ProcessCustomMacro("ConvertUrl", "|(originalURL)http://www.mysite.com/images/blue.gif") %}

case "converturl":
match = true;
string originalURL = sender.CurrentParameters[0, 1];
result = Common.ConvertURL(new UriBuilder(originalURL)).ToString();
break;

even with simpler code, it does not execute:
case "converturl":
match = true;
result = "executed";
break;

it does execute if i use only {% ProcessCustomMacro("ConvertURL", "") %}, but I need to provide the URL to convert. how can I do this?

User avatar
Certified Developer 9
Certified Developer 9
charbf - 10/20/2011 2:10:52 PM
   
RE:custom macro parameters
Hi

what I usually do is this

{% ProcessCustomMacro("gettext|/PathToPage", "") %}

I use the | as parameter seperation

public static string ResolveCustomMacro(MacroResolver sender, string expression, out bool match)
{
match = false;
string result = expression;
// Add your custom macro evaluation

string[] expressions = expression.Split('|');

switch (expression.ToLower())
{
case "gettext":
match = true;
result = GetContent(expressions[1]);
break;
}

return result;
}

User avatar
Member
Member
celeste - 10/20/2011 2:19:58 PM
   
RE:custom macro parameters
I just did that myself. Works beautifully. Thanks!