• Powershell Logo

    Use Sitecore Powershell Console to Find Templates with Layout

    Posted 9/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... Comments (0)
  • Sitecore Languages

    Enforcing Sitecore Languages by Site

    Posted 8/22/2012 by techphoria414

    A question posted on SDN reminded me of a small but powerful pipeline processor we created for a customer that allows you to enforce what languages can be accessed on a particular Sitecore site. As the poster points out, by default Sitecore puts no restrictions on the languages that can be accessed for a given site. So for example, you may only want to allow accessing your Germany site in de-DE, because that's the only language for which you are populating content.

    STEP 1 - The configuration element

    On our site definition, we're going to add a new attribute, enabledLanguages. Values are pipe-delimited.

                <site name="website" patch:after="site[@name='modules_website']"
                    virtualFolder="/"
                    physicalFolder="/"
                    rootPath="/sitecore/content/sample"
                    enabledLanguages="en|de-DE"
                    startItem="/home"
                    database="web"
                    domain="extranet"
                    allowDebug="true"
                    cacheHtml="false"
                    enablePreview="true"
                    enableWebEdit="true"
                    enableDebugger="true"
                    disableClientData="false"
                    formsRoot="{F1F7AAB6-C8CE-422F-A214-F610C109FA63}" />

    STEP 2 - The extension method

    This will allow us to access enabled languages from Sitecore.Context.Site.

    namespace My.Extensions
    {
        public static class SiteExtensions
        {
            private const string _enabledLanguagesAttributeName = "enabledLanguages";

            
    public static string[] GetEnabledLanguages(this SiteContext siteContext)
            {
                if (siteContext == null ||
                string.IsNullOrEmpty(siteContext.Properties[_enabledLanguagesAttributeName]))     
                {
                    return new string[0];
                }
                return siteContext.Properties[_enabledLanguagesAttributeName].Split('|');
            }
        }
    }

    STEP 3 - The pipeline processor

    This processor checks the context language against the site's enabled languages, and terminates request processing if the language is not permitted. Note that we don't enforce a 404 here ourselves, since in theory the default IIS 404 page should take over. YMMV depending on your configuration.

    namespace My.Pipelines.HttpRequestBegin
    {
        public class CountryLanguageEnforcer : HttpRequestProcessor
        {
            public override void Process(HttpRequestArgs args)
            {
                if (Sitecore.Context.Site == null || Sitecore.Context.Language == null)
                {
                    return;
                }

                
    if (!Sitecore.Context.PageMode.IsNormal)
                {
                    return;
                }

                
    var enabledLanguages = Sitecore.Context.Site.GetEnabledLanguages();
                if (enabledLanguages.Length == 0)
                {
                    return;
                }

                
    if (!enabledLanguages.Contains(Sitecore.Context.Language.Name))
                {
                    //don’t process URL. could also directly force 404 here
                    args.AbortPipeline();
                }
            }
        }
    }

    STEP 4 - Configure the processor

    Utilize an App_Config\Include file to patch the processor into the httpRequestBegin pipeline, after Sitecore has completed language resolution.

    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
        <sitecore>
            <pipelines>
                <httpRequestBegin>
                    <processor patch:after="*[@type='Sitecore.Pipelines.HttpRequest.LanguageResolver, Sitecore.Kernel']" type="My.Pipelines.HttpRequestBegin.CountryLanguageEnforcer,My.Classes"/>
                </httpRequestBegin>
            </pipelines>
        </sitecore>
    </configuration>

    ... and there you have it.

    On each site, configure enabledLanguages as needed, based on the languages you are populating for the site.

    Read more... Comments (0)
  • WeBlog 2.2 Released

    Posted 6/2/2012 by techphoria414

    I'm excited to join Alistair Deneys in announcing the release of WeBlog 2.2. You can review the full change log, and Alistair has written a bit about his updates, including a cool new entry summary pipeline.

    My efforts were selfishly centered around updates needed to support Techphoria414 and You-Phoria, a music blog primarily maintained by a good friend. It functions well as a test bed for WeBlog because it features quite a bit of content. 

    My first focus was on performance. I made changes to how the Blog Archive component builds its list of historical posts -- grabbing all posts and sorting them rather than querying by month. I also made some updates to enable HTML caching for sidebar components "by blog." Previously, components such as the category list and archive had to "Vary by Data," meaning they were built and cached for each page of the blog. This is because of the multi-blog scenario. By creating a new sublayout-derivative rendering type, I was able to allow caching to Vary by Blog, so that these components only need to be built once per blog before being cached. The overall result is that WeBlog will now perform much faster, especially for blogs of any size.

    My second focus was allowing the use of different Entry, Category, and Comment templates on a blog-by-blog basis. This cool new feature allows you, for instance, to vary the presentation details for entries and categories for different blogs in the same Sitecore instance. You can read more about Template Settings in the the module wiki.

    Download WeBlog 2.2 from Sitecore Shared Source

    Hope you all enjoy the update. As always, you can provide feedback and feature requests in the WeBlog Forum on SDN.

    Read more... Comments (0)
  • Creating a Sitecore Ribbon Button with a Dropdown Menu

    Posted 6/1/2012 by techphoria414

    This is a neat way to add functionality to the Sitecore Page Editor and Preview. Posted in Q&A format on Stackoverflow:

    How to create a Sitecore ribbon button with dropdown menu?

    Read more... Comments (0)
  • Sitecore Users Virtual Group

    The Sitecore Page Editor: Unleashed

    Posted 5/15/2012 by techphoria414

    Today I had the honor of presenting once again to the Sitecore Users Virtual Group, this time on how to best utilize the Page Editor, as well as some helpful extensions.


    The Webcast


    The Example Code
    You can download the full Visual Studio Solution used for this demo, including a version of the Dynamic Key Placeholder prototype updated for Sitecore 6.5 Update-4. The solution also includes TDS projects with the items needed to run the site.

    The Page Editor: Unleashed Source Code


    Other Helpful Resources

    Sublayout Development with Custom Items and Scriptlets (as seen in example code)

    StackOverflow: Create Content Folder

    Converting Data Source Paths to IDs (John West)

    Add Presentation Component Data Sources to the Links Database (John West)

    Handling Presentation Component Settings (Adam Conn)

    Dynamic Placeholder Keys (Original Article, including working pre-6.5 version)

    Layout Deltas What Ifs (Adam Conn)

    Programmatically Updating Layout Details (John West)

    Advanced Database Crawler (Alex Shyba, as referenced with indexing data source content)

    Cropper (screen capture tool)

    Read more... Comments (4)
  • Team Development for Sitecore

    TDS and Sitecore.* DLLs

    Posted 5/15/2012 by techphoria414

    One fail-safe feature of Team Development for Sitecore that has bit me a few times is its prevention of Sitecore.* DLLs from copying to your web root during a build. Though I appreciate TDS lookin out, there are times when you have non-module libraries, or modified Shared Source libraries, that you do want deployed on build. To work around this, you can utilize the BeforeFileReplacements build target. Place the following in your TDS csproj, just before the closing </Project>, and edit DeploySitecoreBinaries as needed for your assemblies.

    <Target Name="BeforeFileReplacements">
        <!-- restore certain Sitecore.* DLLs that TDS does not copy -->
        <!-- BeforeFileReplacements will be called after TDS has deleted Sitecore.* from its Output, but before it deploys -->
        <ItemGroup>
          <DeploySitecoreBinaries Include="$(SourceWebPhysicalPath)\Bin\Sitecore.SharedSource.Search.dll;
    $(SourceWebPhysicalPath)\Bin\Sitecore.Sharedsource.dll;
    $(SourceWebPhysicalPath)\Bin\Sitecore.Sharedsource.PartialLanguageFallback.dll;" />
        </ItemGroup>
        <Copy SourceFiles="@(DeploySitecoreBinaries)"
    DestinationFiles="@(DeploySitecoreBinaries->'$(_OutputPath)bin\%(RecursiveDir)%(FileName)%(Extension)')" />
      </Target>

    Read more... Comments (4)
  • RSS Speaker

    Sitecore Workflow Emails with rss2email

    Posted 4/5/2012 by techphoria414

    One of the coolest features added by Sitecore way back in 6.2 was Workflow RSS Feeds. My WeBlog cohort Alistair Deneys discussed them a bit back in 2009. I even recall at Dreamcore 2010, Michael Seifert feigning the approval of a press release onstage, using a workflow RSS feed on his smartphone. You can even setup RSS feeds in Outlook, which is a great option for PC users who deal with that wonderful piece of bloatware on a daily basis.

    Workflow RSS in the Workbox
    Workflow RSS feed links in the Workbox. You can see we're very busy moderating comments here at Techphoria414.

    The content and functionality of the RSS feed is great -- it would take a lot of effort to reproduce it in a custom email action. The example below doesn't even show the field-by-field change comparison that's included when an item is updated.

    Sitecore Workflow RSS Content

    Despite the possibilities with RSS, I feel this functionality is really underused. RSS after all these years is still a bit foreign to many non-technical users, and the reality is that in a business setting people aren't paying attention to RSS feeds in the same way they do their email. We even encountered a customer recently who couldn't add RSS feeds to their Outlook client because of a network group policy! So we set out to find a simple solution that allowed us to securely turn the content of the RSS feed into emails for our users. We found it in a cool little tool called rss2email.

    Rss2email does just what it says -- translates an RSS feed into email. It's a small python script which you configure from the command line, then run on a scheduled basis. It's pretty simple to set it up for Sitecore Workflow RSS:

    1. Download and Install Python 2.x
    2. Download and unzip rss2email to a location of your choice, e.g. c:\rss2email.
    3. Copy config.py.example, rename it to config.py and edit as needed. The settings I changed were:
      1. DEFAULT_FROM (something like sitecore-no-reply@mydomain.com)
      2. FORCE_FROM=1 (to ensure the default from address is always used)
      3. SMTP_SERVER (obviously)
    4. Edit r2e.bat to include an absolute path to python.exe. You could also place python.exe in your PATH.
    5. Execute "r2e new <youremail>". This just gives r2e a default email address and creates its data file.
    6. Get the URL of the workflow feed you wish to have emailed. Note: The feeds you pull from the Workbox are specific to each Sitecore user! Be sure to get your user to provide their own feed URL.
    7. Execute "r2e add <feedurl> <useremail>". You likely will need to put the feed URL in quotes.
    8. If you have a lot of existing items in the feed and want to avoid sending the user a slew of emails on first run, execute "r2e run --no-send"
    9. Create a windows scheduled task that executes "r2e run" on a regular basis.

    Your user will now receive an email for each new item entering the Workflow or Workflow State. I'm not giving the rss2email setup process justice, so be sure to reference the rss2email Getting Started guide. Once you have it running, the results are pretty great. In fact, the above screenshot was actually taken from my Google Mail account, not an RSS reader.

    We have a small number of users who need these emails, so maintenance of r2e settings is not a huge issue. On a larger install, it would be interesting to find a way to adapt rss2email, or automate the addition/removal of users and their feeds. But quick and easy is what we were looking for, and this certainly delivered. Big thanks to Lindsey Smith for this tool.

    Read more... Comments (2)
  • Glimpse Logo

    Glimpse Debugging for Sitecore

    Posted 3/28/2012 by techphoria414

    While I have my gripes about the implementation of Sitecore.Context as essentially a repository for global variables, there is no doubt that the concept provides a great deal of the flexibility of the platform. But this flexibility can also create headaches in debugging. Context item, database, language, device... and further how they're used to construct and apply renderings. There's a lot going on in constructing just a single page. How can we securely expose information about the context to help debug published pages, even in production?

    Glimpse is a debugging tool which espouses that "what Firebug is for the client, Glimpse does for the server." It securely and transparently adds a client-side debugging interface to your output pages.

    Out of the box, Glimpse provides all kinds of information on what's going on with the server side of your ASP.NET Webforms or MVC application. What if we could extend this UI to include information about the Sitecore Context and other page information? The Glimpse site already provides a lot of great information on what Glimpse does and how to install Glimpse. It also provides a nice tutorial on its dead-simple plugin architecture.

    To create a Sitecore plugin for Glimpse:

    • Install Glimpse using NuGet.
    • Create a new class library in your solution.
    • Reference Glimpse.Core, System.ComponentModel.Composition, and System.Web assemblies
    • Create a new class that implements IGlimpsePlugin
    • Mark your class with the attribute [Glimpse.Core.Extensibility.GlimpsePluginAttribute()]
    • Implement the GetData method to return a List of object arrays containing your debugging data
    • Implement the Name property to return the string "Sitecore"
    • Drop your new assembly into your Glimpse-enabled application

    The result may look something like this:

    Sitecore Debugging with Glimpse
    click to enlarge

    Download an example Glimpse plugin for Sitecore

    You can either integrate this project with your solution if you'd like to make modifications, or include the built assembly as-is in your Glimpse-enabled project. It provides some basic information about the page, but I could certainly envision extending this to include more information, akin to the Sitecore Debug view.

    UPDATE: In April 2012 there was a Sitecore User's Virtual Group meeting in which David Morrison from Sitecore showed off his more advanced Sitecore Glimpse plugin.

    Read more... Comments (2)
  • Powershell Logo

    Changing Item Templates With Sitecore PowerShell

    Posted 3/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... Comments (2)
  • Techphoria414

    T414 Sitecore Best Practices Part 3: Sublayout Development with Custom Items and Scriptlets

    Posted 2/8/2012 by techphoria414

    The T414 Sitecore Best Practices Series is a screencast overview of the foundational pieces we use at Hanson Dodge Creative in our Sitecore development projects. Part 3 demonstrates our approach to creating Sublayouts using custom item classes (generated by the Custom Item Generator shared source module) and scriptlet-based user controls for efficient, clean Sitecore development that's Page Editor friendly. I've outlined this approach in a previous post as well.

    Part 1: Introduction to TDS is available here.

    Part 2: Solution Structure and Working with TDS is available here.

    Read more... Comments (0)
View more
Sitecore MVP

Syndication

Recent comments