Skip to content

Instantly share code, notes, and snippets.

@DominicCronin
Created January 13, 2015 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominicCronin/a5b871362921a408c8ef to your computer and use it in GitHub Desktop.
Save DominicCronin/a5b871362921a408c8ef to your computer and use it in GitHub Desktop.
Suffix Binaries With Id
[TcmTemplateTitle("SuffixBinariesWithId")]
public class SuffixBinariesWithId: ITemplate
{
public void Transform(Engine engine, Package package)
{
string paramMimeTypesToMatch = package.GetValue("mimeTypesToMatch");
// match all image types by default
string mimeTypesToMatch = "image/*";
if (!string.IsNullOrWhiteSpace(paramMimeTypesToMatch))
{
mimeTypesToMatch = paramMimeTypesToMatch;
}
foreach (var item in package.GetAllByType(new ContentType(mimeTypesToMatch)))
{
// Items with property filename are multimedia
if (item.Properties.ContainsKey(Item.ItemPropertyTcmUri)
&& item.Properties.ContainsKey(Item.ItemPropertyFileName)
&& !item.Properties.ContainsKey(Item.ItemPropertyFileNameSuffix))
{
TcmUri uri = new TcmUri(item.Properties[Item.ItemPropertyTcmUri]);
item.Properties[Item.ItemPropertyFileNameSuffix] = "_" + uri.ItemId.ToString();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment