XSLT function only renders in preview in the console

Topics: XSLT
Sep 18, 2016 at 3:27 PM
Hi
Is it possible to make a xslt-function that only renders whatever it is assigned to do inside the C1 console in the preview tab?

Meaning wrapping the code in a xslt:if statement where the value is some parameter that returns true if we are inside the console or something like that
Coordinator
Sep 19, 2016 at 10:11 AM
It is doable - you first need to create a new C1 Function that expose the value of PageRenderer.RenderingReason and then include this in your XSLT. Your new function you can make as a C# Function.

See http://docs.composite.net/Functions/Orckestra-CMS-API/Rendering-Reason for more info on RenderingReason.
Sep 20, 2016 at 12:07 PM
OK, Does anyone by any chance have a simple example of an inline C# function that exposes the RenderingReason value. I'm quite fucked when it comes to C# :-/
Is there any documentation on how to include C# functions in xslt. Can't seem to find any on this
Coordinator
Sep 20, 2016 at 12:19 PM
Add Inline C# Function
  • Name: PageRequestReason
  • Namespace: Composite.Web.Request
  • (click "Finish")
Paste in code below and save.
using System;
using Composite.Core.WebClient.Renderings.Page;

namespace Composite.Web.Request
{
    public static class InlineMethodFunction
    {
        public static string PageRequestReason()
        {
            return PageRenderer.RenderingReason.ToString();
        }
    }
}
This should give you a new function Composite.Web.Request.PageRequestReason which return one of the following string values, depending on the context of a page rendering:
    /// Undefined (computer language for "what?? No page is being rendered now, why are you calling me??")
    Undefined

    /// A page was requested through a browser
    PageView

    /// A page is viewed from C1 Console's browser
    C1ConsoleBrowserPageView

    /// A page is reneder from withing an "Edit page" workflow
    PreviewUnsavedChanges

    /// A page is rendered to generate an image to be used for function/template visualization
    ScreenshotGeneration
Hope this helps!
Sep 20, 2016 at 3:04 PM
It does help a lot, Only 1 thing: If I insert the function in the xslt ( <f:function xmlns:f="http://www.composite.net/ns/function/1.0" name="Composite.Web.Request.PageRequestReason" /> ) it prints out the values as it should. I would like to inject it to a xslt variable to test the string like:
<xsl:variable name="pageView">
    <f:function xmlns:f="http://www.composite.net/ns/function/1.0" name="Composite.Web.Request.PageRequestReason" />
</xsl:variable>
This doesn't work. Am I going the wrong way?
Coordinator
Sep 21, 2016 at 10:01 AM
Edited Sep 22, 2016 at 9:43 AM
In your XSLT add a call to the PageRequestReason function as an input to your XSLT (i.e. add the call on the "Functions" tab) - then you get the info in the XML document your XSLT is working on.
Sep 21, 2016 at 2:56 PM
Yes of course, thanx alot, You da man mawtex!!