Passing parameters from page into snippets within a slot

Maybe I’m being stupid here (runs for cover) but I’ve a question about passing custom parameters from my page template into the snippets that are being assembled within a slot.

I have a snImageLink snippet and I’d like to pass a parameter into it so that the assembly URL for the snippet has at the end of it “&imageClass=floatRight” (or similar).

Within my page template (which includes my slot containing image link content items) I want to do the following:

#slot ("myImageSlot" "" "" "" "" "imageClass=floatRight")

My imageClass parameter doesn’t make it as far as the snippet assembler (if I output $sys.params in the snippet template). I guess this is because the only parameters I can use are ones that my slot content finder can make use of (e.g., template, max_results, etc.).

Is there a way to get my customer parameter passed into the assembly url for the snippets in my slot?

Amy I missing something obvious here…

David,

No, HTML parameters that you set in the page template don’t make it to the snippet. This came up recently at another customer/partner implementation that I’ve been working on.

Our solution was to pass the parameter in the bindings map.

In your “page” template:

#set($xyz = $sys.assemblyItem.bindings.put('$foo', "bar"))

In your snippet template:

<p>Binding for foo is: $foo</p>

Notes:

  1. The name $foo must be in SINGLE quotes to prevent expansion of $foo in the set statement
  2. The value of $xyz will be NULL. This value is never needed anywhere, but don’t use a variable whose value you care about.
  3. Your snippet should not break if $foo is null (use #if to isolate any sections that need $foo). Otherwise you will not be able to preview the snippet.

Let me know if this works for you

Dave

It most certainly does. Thank you.

Actually, there’s one small error in my previous post.

The value of $xyz will be the PREVIOUS value of $foo, which in most cases will be null. There may be some instances where you want to set some variable and then reset it when you are done, but in most cases this is not necessary.

I’m glad it’s working for you

Dave

I was just trying to figure out if this was possible today. I’m going to be updating our nav bar so the current selected nav item is highlighted and I wanted to pass the system title or the content item ID to the snippet template to compare it to the item retrieved by the auto slot.

Mike,

The currently selected nav item is available as $nav.self. You should be able to use this variable to highlight the current item without passing in any parameters.

If this isn’t what you are attempting, please let us know and we’ll help you figure it out.

Dave

You need to remember with this technique that you are setting the bindings of the page template, not just passing parameters to the snippet template used by the slot you call immediately afterwards. Those modified bindings will be inherited by any slots further down the page, slots inside snippets, the global template, and any snippet templates used by slots called from the global template (e.g. navigation slots.) So unless your site is very simple, you’ll probably want to have a system of default values, and set bindings back to their default values after each slot call.