Tuesday, 30 April 2013

Add CSS / JavaScript to custom Publishing Page layout

Ever wondered how to add css / Javascript into a custom publishing page layout.  I did!!!!  Just add the PlaceHolderAdditionalPageHead content placeholder tag and voila!!!!

<asp:Content ContentPlaceholderID="PlaceHolderAdditionalPageHead" runat="server">
<style type="text/css">
  //some css
<script type="text/javascript">
 //some js

Invalid Associated Content Type

Recently I have been working on a project creating custom publishing page content types and layouts in Visual Studio.  All seemed fine, the deployment went as expected and off I went to create my new page based on the custom content type / page layout I had created. After selecting the content type from the menu I was redirected to the create page when i noticed that the page layout option was preceded with the words "(invalid Associated Content Type)".  Having never seen this before I was at a lost.  I did a quick retract and deploy to see if something had gone wrong during the deploy to no avail.  Being a bit lost at this point i fired up chrome and copied the error message into google.  A quick scan of a few websites revealed my problem.  It seems you need to reference the content type in the content type like so:-

<FieldRef ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Name="ContentType" />

A quick redeploy and test verified that this did indeed solve my problem.  Don't ask me why!!!!!!