Show the number of Coveo results in facets within brackets

Last Thursday evening out of the blue, the client asked to see the result count inside of brackets. It is a very intuitive feature that gives the searcher an indication of the big picture when searching and filtering.

The PROBLEM:


The ASK:

We were using the Coveo Atomic component, but there was no reason to not show the results inside brackets as it was the default behavior anywhere else. After much debugging, there was no indication of why the numbers were not within brackets but the client wants what the client wants. so, we took a short and simple way of implementing it using CSS.

.coveo {
  .coveo-facet-value-count:before, .coveo-facet-value-count:before {
    content: "(";
  }
}

This solved all our problems and the client lived happily ever after.

~ Unless you are easily worried about everything, try not to stress. ~

Content Hub Web SDK – Programmatically update assets in Content hub from items in Sitecore

Getting the entity

IEntity entity = await _connector.Client.Entities.GetAsync(long.Parse(assetId));

assetId can be a string or a long. The string is mostly used when IDs look like an alphanumeric hash. If we want an image with asset Id of 99551 then use long.

Getting a relationship with an entity

IRelation relation = entity.GetRelation("AssetTypeToAsset");
IList<long> values = relation.GetIds();
//if (values.Count == 0) then we know there is no value set, otherwise there is already a value set for that relation

Setting up a related value

IEntity imageAssetEntity = await _connector.Client.Entities.GetAsync("M.AssetType.Custom");
IChildToOneParentRelation assetEntityRelation = await entity.GetRelationAsync<IChildToOneParentRelation>("AssetTypeToAsset");
assetEntityRelation.Parent = imageAssetEntity.Id.Value;
//This will set up the selected asset entity's AssetType as Custom

Set a property for an entity

string alt = item["Alt"] ?? "";
ICultureInsensitiveProperty altProperty = entity.GetProperty<ICultureInsensitiveProperty>("Alt");
altProperty.SetValue(alt);
//This will get the Alt field value of an item from sitecore and update an asset with that value in the Alt property

Debug your code and attach it to processes running inside Docker

There I was, one fine afternoon, having a deep-fried twinkie and writing some commands for Sitecore. Sitecore was running in docker. so every code change, build, deploy, and sometimes run up.ps1 if there is an error, and cross my fingers and test the command. I wanted to attach Visual Studio to the w3wp process running on the cm image.

In Visual Studio follow these steps

Select Docker from the connection type dropdown

Click on “Find”
is this is your first time, visual studio will install a package in your docker from nuget so that it’s discoverable

Once you are connected to the right image

find your process and attach it.

Enjoy all your breakpoints.

~ Do not block someone else’s driveway. They may have to go somewhere. ~

Use JSON path when setting up a Trigger condition in Sitecore Content Hub

The problem

Create public links for a specific rendition of all assets except for when a document is created or uploaded.

The brain

All assets have file properties that are part of the system OOTB metadata.

I know a trigger on asset change and action that runs a script is the easiest way to get this done. We could add conditions on a trigger to check the asset type relation and then run a script to create a public link. if all else fails look at a custom solution.

The struggle

Trying to load an asset and its related media and types is a little icky. You can read the entity and try to find the type. If it’s an image, video, or document one can decide to run different tasks. FileType, fileName, and File Property metadata all are accessible but a little convoluted to get and check. So I picked a GUI path and just check the asset file property on the trigger condition. so the trigger won’t even fire let alone check inside the script for a valid scenario.

This was a simple solution, but the only problem was finding an example of how to read JSON values in conditions. Thus I gave birth to this blog post. Just type in property names in the path field and trigger works as expected.

Related links to click if you need to.

https://doc.sitecore.com/ch/en/users/34/content-hub/manage–ootb-schema.html

https://www.sitecored.com/2021/09/sitecore-content-hub-automatically-assign-asset-type.html

~ Do not overdo it. If you can, you will do it. If you can’t, someone else will do it. ~

Download Images from PixelSet.com

PixelSet.com has a nice feature of downloading pictures from a gallery one at a time.

but I needed to bulk download all or some pictures.

Found these Chrome extensions to be useful.

Here is another nifty trick, on the developer tool console

Type in $(‘.gamma-description-wrapper’).siblings(‘img’)[0].src

This will give you the url, which you can then open in new tab and download that image.

Enjoy…

~ Life is not fair. You have to make it so. ~

The problem with multiple Sitecore instance management, using favicons.

Like thousands of other developers, our there who are working with Sitecore will face this problem.

The problem:

  • Working with multiple environments.
  • Working with multiple clients.
  • Working with duplicated tabs of Sitecore backend.

Screen Shot 2020-03-30 at 6.08.04 PM

There are multiple solutions out there.

  • Modifying the header area to mention the environment or database.
  • Updating the color to determine the environment.
  • Working with the configs to change the look for the backend.

But what I was looking for is to know before I clicked on the tabs as seen above. The page title and the favicons were the easiest things to change for that.

Just go to your site’s root/Sitecore/images/ and replace the favicon.ico with your client’s favicon.

That’s it. Now I know who’s Sitecore I will be unleashing before I open the tab. I found this to be the least intrusive and simplest solution to my problem.

Let me know if you know a better way. Please.

 

~ Be kind, be brave, be happy.~

Make Sitecore look good Again. Tip #2012: Add custom CSS to Launchpad

If you are like me, you are looking at Sitecore Launchpad if you are looking at light or dark Visual Studio all day and night, and sometimes in your dreams.

03

I needed to make some lifestyle changes, so I decided to try to change the layout and look of the Launchpad. As usual planning and research and actually finding the time to do this took way longer than the actual task.

I went deep into Sitecore. Learned about injecting JS and CSS into pipelines here, Things like adding a button to Launchpad, Adding controls in Content Editor in the Core database. Watched youtube videos with weird titles.

But at the end of the day, what I wanted to accomplish was really simple.

Go to your core database and find this item. /sitecore/client/Applications/Launchpad/PageSettings/

Add a new Page-Stylesheet-file item with a link to your CSS file.

Screen Shot 2020-03-30 at 11.15.30 PM

Guess what? That’s it.

My Launchpad now looks like below.

Screen Shot 2020-03-30 at 11.17.23 PM

Want the CSS. Here is it.

.sc-launchpad-group-title{
	margin-bottom:15px;
}

.sc-launchpad-group-row{
	height:auto;
	width:170px;
}

.sc-launchpad-item{
	display:contents;
	width:170px;
	position:relative;
	height:45px;
}

.sc-launchpad-item .icon{
	width:40px;
	height:40px;
	float:left;
	border:none;
	margin:0px;
	margin-bottom:10px;
}

.sc-launchpad-item .icon img{
	width:30px;
	height:30px;
	margin:5px 0px 0px 0px;
}

.sc-launchpad-item .sc-launchpad-text{
	height:41px;
	width:130px;
	max-width:130px;
	margin-bottom:10px;
	background-color: #f7f7f7;
    background-image: -webkit-linear-gradient(white, #f7f7f7);
    background-image: -o-linear-gradient(white, #f7f7f7);
    background-image: linear-gradient(white, #f7f7f7);
	text-align: left;
    padding-top: 5px;
    padding-left: 5px;
}

.sc-launchpad-item .sc-launchpad-text:hover{
	background-color:white;
	background-image:none;
}

 

 

~ Don’t change what’s inside of you. Change what’s around you.~

Make Sitecore Look Good Again. Tip #3021: Add CSS to the content tree items

Let’s make Sitecore beautiful. Here is a very little known thing that I personally haven’t seen getting too much attention but is a neat trick to show off your skillz.

Select the Item. Go to the configure tab. Then “Tree node style”. Enter all the CSS styles you know and want to show.

Screen Shot 2020-03-15 at 5.48.49 PM

Be careful: A bit of wrong, weird or malformed CSS could break this. and you will the red screen of death next time you try to go to the Tree Node Style window.

To clean that up I usually spin up http://<your-sitecore>/sitecore/admin/dbbrowser.aspx

and go to the item’s style value and clean that up.

Screen Shot 2020-03-15 at 6.13.47 PM

 

~ Enjoy the colors around you. ~

See who is logged in to your Sitecore CM environment

Who had this problem where you have to make some changes to your CM server, you told the authors to get out, but they never leave. They love Sitecore so much you can’t get them out by themselves.

So, I wanted to know who is using the server at the time. and thus created a page that lists the logged-in users at that time.

Sitecore has this functionality on the kick users/boost user page. So, that’s where I started. Did you know /sitecore/admin/sessionsummary.aspx is a page that’s actually there. But it doesn’t work. I get 500 error. Screen Shot 2020-02-14 at 3.19.04 PM

 

So, Dotpeek it is and I made the following.

@{
	List<Sitecore.Web.Authentication.DomainAccessGuard.Session> newList = Sitecore.Web.Authentication.DomainAccessGuard.Sessions;
}
<div><h3>Maximum Sessions Allowed in this instance:</h3>  @Sitecore.Web.Authentication.DomainAccessGuard.MaximumSessions</div>
<div>
@if (newList.Any())
{
	<H3>logged in users:</H3>
	<table border="1">
	<tr>
		<td>Session ID</td>
		<td>User Name</td>
		<td>Created Date</td>
		<td>Last Request Date</td>
		<td>Active For (Minutes)</td>
	</tr>
	@foreach (var dg in newList)
	{
	<tr>
		<td>@dg.SessionID</td>
		<td>@dg.UserName</td>
		<td>
			@DateTime.Parse(dg.Created.ToString()).ToLocalTime()
		</td>
		<td>
			@DateTime.Parse(dg.LastRequest.ToString()).ToLocalTime()
		</td>
		<td>
			@((int)((dg.LastRequest - dg.Created).TotalMinutes))
		</td>
	</tr>
	}
	</table>
}
</div>

 

I stuck this in my /Sitecore/admin folder, or put it wherever you need.

This will give you following page.

Screen Shot 2020-02-14 at 3.22.24 PM

I added an auto-refresh on the page as well just for fun, you all know how to do that, right 🙂

Enjoy!!!

 

~ Fight, Flight, Food & Fuck, The four F’s of Life’s Basics. ~

Register Bundle not registering Bundle?

I have a not-so-custom register bundle pipeline.

<processor type="namespace.Pipelines.Initialize.RegisterBundles, namespace" />

It’s supposed to bundle all my CSS and js into one file.

But it was NOT, thus this post.

 

ALL I had to do is to remember that I was building the solution in debug configuration mode. Bundling doesn’t happen if you are not in RELEASE mode. so, please change your Build configuration to release and save yourself some debugging time when deploying an app.

 

 

 

~ Life is not a sprint, it’s a marathon. ~