Created
January 13, 2015 10:25
-
-
Save DominicCronin/a5b871362921a408c8ef to your computer and use it in GitHub Desktop.
Suffix Binaries With Id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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