Skip to content

Instantly share code, notes, and snippets.

View DominicCronin's full-sized avatar
💭
Still Upskilling on Azure DevOps.

Dominic Cronin DominicCronin

💭
Still Upskilling on Azure DevOps.
View GitHub Profile
@DominicCronin
DominicCronin / gist:786e8b00d21c538b1de5
Created November 4, 2014 21:41
Create Tridion Publications
# Depends on Tridion Powershell Modules (http://code.google.com/p/tridion-powershell-modules/)
function createPublication {
Param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$core,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$title,
@DominicCronin
DominicCronin / gist:a5b871362921a408c8ef
Created January 13, 2015 10:25
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))
{
@DominicCronin
DominicCronin / gist:fcc3397a21bda19f4cb8
Created January 13, 2015 10:46
Add Component Id to Binary Filename
// componentUri is a TcmUri representing the id of the binary component that you want to publish
// This snippet shows how you can add the item id to the filename.
var component = (Component)engine.GetObject(componentUri);
var filename = component.BinaryContent.Filename
extension = Path.GetExtension(filename);
filename = Path.GetFileNameWithoutExtension(filename);
filename = String.Concat(filename, "_", componentUri.ItemId.ToString(), extension);
engine.AddBinary(component.Id, null, null, component.BinaryContent.GetByteArray(), filename);
$params = @{
client_id='cduser'
client_secret='CDUserP@ssw0rd'
grant_type='client_credentials'
resources='/'
}
$token = Invoke-RestMethod -Uri 'http://localhost:9082/token.svc' -Method POST -Body $params
$Authorization = $token.token_type + ' ' + $token.access_token
[ComponentPresentations]
public List<IRenderableViewModel> ComponentPresentations { get; set; }
@foreach (var cp in Model.ComponentPresentations.Where(cp => cp.RenderData.View == "ContentBlock"))
{
@Html.Render(cp)
}
public List<IRenderableViewModel> ContentBlocks {
get
{
return ComponentPresentations
.Where(cp => cp.RenderData.View == "ContentBlock")
.ToList<IRenderableViewModel>();
}
}
@foreach (var cp in Model.ContentBlocks)
{
@Html.Render(cp)
}
[PresentationsByView(ViewPrefix ="ContentBlock")]
public List<IRenderableViewModel> ContentBlocks { get; set; }
# Setup
$publicationId = 20 # The publication where your content is published
# Broker database - substitute your own settings here.
$connStringBuilder = new-object System.Data.SqlClient.SqlConnectionStringBuilder
$connStringBuilder["Data Source"] = "WEB8,1433"
$connStringBuilder["Initial Catalog"] = "Tridion_Broker"
$connStringBuilder["User ID"] = "TridionBrokerUser"
$connStringBuilder["Password"] = "Tridion1"