• Powershell Logo

    Use Sitecore Powershell Console to Find Templates with Layout

    Posted 09/12/2012 by techphoria414

    Undoubtedly someone will tell me an easier way to do this after I post, but was just saved by the Sitecore Powershell Console module yet again. Used it to find references to my base layout underneath /sitecore/templates -- i.e. templates that have a layout assigned on their standard values. Pretty snazzy.

    PS master:\layout\Layouts> $layout = get-item BaseLayout
    PS master:\layout\Layouts> $linkDatabase = [Sitecore.Globals]::LinkDatabase
    PS master:\layout\Layouts> $links = $linkDatabase.GetReferrers($layout)
    PS master:\layout\Layouts> $links | foreach-object { if ($_.GetSourceItem() -and $_.GetSourceItem().Paths.Path.ToLower().StartsWith("/sitecore/templates")) { write-host $_.GetSourceItem().Paths.Path } }
    /sitecore/templates/snip/Event/Event/__Standard Values  
    /sitecore/templates/snip/Generic/Generic Article/__Standard Values  
    /sitecore/templates/Branches/snip/Site Root/$name/Home/Products/Categories  
    /sitecore/templates/snip/Generic/Generic Detail/__Standard Values  
    /sitecore/templates/snip/Education/Category/__Standard Values   
    /sitecore/templates/snip/Home/__Standard Values  
    /sitecore/templates/snip/Error/__Standard Values  
    (etc)

    Looks like I have some branch templates to look at too.

    Read more...
  • Powershell Logo

    Changing Item Templates With Sitecore PowerShell

    Posted 03/19/2012 by techphoria414

    So I'm starting to explore the Sitecore PowerShell Console module from Adam Najmanowicz, and I think the community could benefit from a few more example scripts. I'm working on some enhancements to WeBlog that will allow you to more easily use different templates for each blog, which required me to change the template of a large number of entries. PowerShell made this easy once I figured it out:

    $master = [Sitecore.Configuration.Factory]::GetDatabase("master");
    $entryTemplate = $master.Templates["YouPhoria/Blog/Entry"];
    cd master:\Content\Home\Blog\;
    Get-ChildItem -recurse | ForEach-Object { if ($_.TemplateName -eq "BlogEntry") { $_.ChangeTemplate($entryTemplate) } };

    And there you go.

    Obligatory note: You could also do this using Revolver, a command prompt module from my WeBlog partner in crime Alistair Deneys.

    Read more... Pre-Disqus Comments (4)
Sitecore MVP

Popular Posts

Syndication

Archive