Conditional HTML within slot

Hi,
Is it possible to change the HTML of a snippet conditionally based upon whether or not it is contained in a certain slot?
I have an

<img>

tag where I want to display the alt attribute under certain circumstances but not when it’s contained within a slot which has an enclosing

<a>

tag.
It would seem that the snippet would have to have some knowledge of the slot it was included in.
Thanks.

You can pass additional parameters into the slot when you use #slot or #initslot macros. Just pass in a string that looks like the params part of an HTML query request…

Example:
#slot( “MySlotName” “header” “item-prefix” “item-postfix” “footer” “foo=bar&google=plex” )

or

#initslot( “MySlotName” “foo=bar&google=plex” )

If you are galling the $sys.asmhelper.assemble() method directly, then you have to prep the param string a little bit beforehand.

#set($completeparams = $rx.asmhelper.combine($sys.params,“foo=bar&google=plex”))
#set($results = $rx.asmhelper.assemble($sys.assemblyItem,$sys.asm.findSlotByName($slotname),$completeparams)

Once you’ve done this, then your snippet template can check the value of your param with $rx.asmhelper.getSingleParamValue($sys.params,‘foo’) and you can base your conditional statements around this value.

Happy hacking!

I just tried this and $sys.params contains all the usual sys_XXXX parameters but none of the ones I passed using #slot.
So $rx.asmhelper.getSingleParamValue($sys.params,‘YYYYY’) in the slot snippet doesn’t return anything.
Did I miss something?

Holy moley… you’re right… back to the drawing board…

Even though that should have worked… it appears that something is lost in the translation from parent item to slot item… so, here’s another way to do it:

in the parent template, just before calling your slot, add the parameter to the current assembly item with something like this:

$sys.assemblyItem.setParameterValue('foo','bar')

Yes it’s a little crazy and you shouldn’t have to do it this way, but at least the param gets passed to the slotted item’s template.

Could we get a Percussion Support person to chime in on why the code I provided earlier doesn’t work?

Looks like the extra params in the #slot macro are only supplied to the AutoSlotContentFinder, and not passed into the related item assemblers, so adding the extra param to $sys.assemblyItem is the only way to pass a value to a slot through a parameter…

Although, I’ve seen, in another recent thread, that apparently, variables from the parent template’s scope are also passed as a copy into the child template’s variable space.

Thanks, Rushing, that’s exactly what I wanted. Works perfectly.