Related content browser snippet preview

I’ve devised a way to wrap a snippet in dummy containing divs if it’s being viewed using regular snippet preview from the content explorer, with these divs being dropped if the item is in a page. This means the snippet looks as it would in a page.

I’ve also managed to set a default rxs_navbase value for when a user is in the active assembly table editor and clicks a related item snippet preview, which has no site or folder id passed to it, so that also renders my snippets relatively well - there may be a better way to do this, I suppose by trying to look up the id of the containing folder and thereby the site id and not trying to pick up the rxs_navbase value until those values are populated.

But for the life of me I can’t work out how to get the related content browser, when looking for a snippet to attach in a slot, to show anything resembling what the snippet will actually look like, ie apply any styles.

Anyone got any hints?

Hi,

I’d be in your debt if you would share how you accomplished those two things. I’ve been banging my head against the wall trying …

Thanks,

Matt

Sure.

At the top of every snippet and page template I call a macro:

#lg_setvariables()##

This macro, in rx_assembly.vm (System Design > User Velocity Macros) does this:

#macro(lg_setvariables)##
#if($containingtemplate)#set($iscontained=true)#else#set($iscontained=false)#end##
#set($xyz = $sys.assemblyItem.bindings.put('$containingtemplate', $rx.asmhelper.getSingleParamValue($sys.params,'sys_contentid')))##
#if(!$rxs_navbase)#set($rxs_navbase="../web_resources/lgrb")#end##
#end

This essentially puts a binding called $containingtemplate available to each contained snippet. If a page has come along and set the binding then the value is set, and it’s a different id from the id of the snippet. If it’s not been set then the snippet is being previewed alone.

Then it also sets a default $rxs_navbase should the binding in the template not have found a value from the publishing variables.

After that, we can contain a snippet thus:

<body class="landing generic">
	#if(!$iscontained)
	<div class="generic-cols-3 clear">
	<div class="generic-col-1">
	#end
	<div class="feature-txt-box tint-9">
		<div class="open-quote"> </div> 
			<div class="quote-content tint-9"> 
				<p>#field("longcallout")</p>
				<p class="author">#field_if_set("" "displaytitle" "" ) 
				#field_if_set(", <br/>" "linktitle" "" )</p>
			</div> 
		<div class="close-quote"> </div> 
    </div>
	#if(!$iscontained)
	</div>
	</div>
	#end
  </body>

Also, I’ve put my call to render stylesheets in a macro so I just call the same macro for every page/snippet so it only needs to be changed once.

Thanks so much for your reply. I will give it a try.

Matt