Moosecore #6; Placeholders and GlassCast
Following the method of organizing everything into Component folders, SubLayouts now has a /Component/Identity folder where the header sublayout will live.
After searching around, I finally found the developer center where I can create this file. Can I do this in VS instead?
After searching around, I found that this was the dumb way to do it: I can just add the folder and file directly in VS, and it will copy over.
This is a lot cleaner, and will be easier to manage with Git.
In trying to show the inherited Logo image, I start getting confused with this line of code:
<xsl:variable name = "siteRoot" select="ancestor-or-self::item[sc:IsItemOfType('_Identity',.)]"/>
This seems to set a variable for this next bit, but the syntax confuses me and seems awfully unclear.
<div class = "Logo"> <sc:image select = "$siteRoot" field="Identity_SiteLogo"/> </ div >
This makes far more sense - grab the variable, and display a field from it.
After half of hour of trying to get the Header to render on the page correctly, and pulling the help of two team members, I find out that my placeholders were missing Keys! My placeholders now look like:
<sc:placeholder runat="server" key="HeaderRegion" id="HeaderRegionPlaceholder" />
I also learn that XSL is old and that I should use either GlassCast or CustomItemGenerator to grab the root element. Time to learn something new!
From what I can tell, GlassCast takes items in Sitecore and generates code templates for them, and lets us convert items between each other as if they inherit each other like classes - because that's that it does, it generates classes for items. I think.
I use this tutorial as a loose guide, but frankly I have no idea what I'm doing. This seems like an excessive amount of work just to grab the Image off of a parent item.
First step is installing GlassCast, which is already confusing. There are several packages, and I'm not sure what each one is for.
I install the option that seems to make the most sense, which auto-installs the base package.
Next, I (probably) enable the Code Generation on the TDS project
The code generation relies on templates to run, which Hedgehog has graciously provided in a Github repository here
Following the tutorial, I add the following .tt files: GeneralExtensions, GlassV3Header, GlassV3Item, Helpers, Inflector, and StringExtensions
I select the GlassV3 .tt's as the transform files, but code generation fails.
As it’s the first time generating you may get an error that the file already exists. Just show all files in Solution Explorer and you’ll see the generated class file in the Models folder. Add this to the project and you should be able to continue to generate the file without the error.
I have to reopen VS and rebuild the project, but code generation finally succeeds and it seems to have worked.
Next up, we try to use the code behind!