Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ryan Green 63 posts 83 karma points
    Oct 02, 2012 @ 17:03
    Ryan Green
    0

    Some sort of a conditional statement based on current URL?

    In ColdFusion (where I came from) we could do something like this:

    <cfif CGI.PATH_INFO Contains "mobile">

    Excute this code....

    <cfelse>

    excute this code...

    </cfif>

    But is there a way to do this in Umbraco ?

    Is there  a way to check to see if the current page has the word "mobile" in the URL. If it does, than load for a page URL:

    <href="{umbraco.library:NiceUrl(@id)}?altTemplate=mobile" class="xsltsearch_title">
    <xsl:value-of select="@nodeName"/>
    a>

    If it doesn't contain "mobile", load this

    <href="{umbraco.library:NiceUrl(@id)}" class="xsltsearch_title">
    <xsl:value-of select="@nodeName"/>
    a>

     

    Basically, I want the code to redirect to the mobile formatted page, but only if it is coming from a mobile formatted page.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Oct 02, 2012 @ 17:58
    Chriztian Steinmeier
    0

    Hi Ryan,

    You can use umbraco.library:RequestQueryString() to check that:

    <!-- Check if this is a mobile request -->
    <xsl:variable name="mobileRequest" select="umbraco.library:RequestQueryString('altTemplate') = 'mobile'" />
    
    <a class="xsltsearch_title">
        <xsl:attribute name="href">
            <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
            <xsl:if test="$mobileRequest">
                <xsl:text>?altTemplate=mobile</xsl:text>
            </xsl:if>
        </xsl:attribute>
        <xsl:value-of select="@nodeName" />
    </a>

    /Chriztian

  • Ryan Green 63 posts 83 karma points
    Oct 02, 2012 @ 18:44
    Ryan Green
    0

    That is exactly what I am looking for, but I am using the alternate version of the altTemplate string that doesn't use a query parameter.

    so it is actually:

    /search/mobile

  • krishnaraj padeyannawar 3 posts 23 karma points
    Oct 02, 2012 @ 18:48
    krishnaraj padeyannawar
    0

    Server Error in '/Web' Application.


    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       SmartSource.MRWeb.SSOAuthenticationHandler.ProcessRequest(HttpContext context) in C:\inetpub\wwwroot\MediaRemoval\Site\SmartSource.MRWeb\SSOAuthenticationHandler.ashx.cs:34
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +598
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +170
    



    Version Information: Microsoft .NET Framework Version:2.0.50727.4971; ASP.NET Version:2.0.50727.4971

  • krishnaraj padeyannawar 3 posts 23 karma points
    Oct 02, 2012 @ 18:59
    krishnaraj padeyannawar
    0

    Server Error in '/Web' Application.


    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       SmartSource.MRWeb.SSOAuthenticationHandler.ProcessRequest(HttpContext context) in C:\inetpub\wwwroot\MediaRemoval\Site\SmartSource.MRWeb\SSOAuthenticationHandler.ashx.cs:34
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +598
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +170
    



    Version Information: Microsoft .NET Framework Version:2.0.50727.4971; ASP.NET Version:2.0.50727.4971

  • Ryan Green 63 posts 83 karma points
    Oct 02, 2012 @ 19:12
    Ryan Green
    0

    What is the last two posts supposed to be? All I get is Server Errors ?

    Chriztian,

    I think that would work, but since I am still really new to Umbraco, I am looking for a way for it to say

    If the URL contains "mobile" Then .....

     

    /rg

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Oct 02, 2012 @ 23:39
    Chriztian Steinmeier
    0

    Hi Ryan,

    You can get all the usual HTTP headers with umbraco.library:RequestServerVariables() - I guess something like:

    <!-- Grab the URL  -->
    <xsl:variable name="currentURL" select="umbraco.library:RequestServerVariables('URL')" />
    
    <!-- Check if this is a mobile request -->
    <xsl:variable name="mobileRequest" select="contains($currentURL, '/mobile')" />
    
    <!-- NiceURL for this page -->
    <xsl:variable name="niceURL" select="umbraco.library:NiceUrl(@id)" />
    
    <a href="{$niceURL}" class="xsltsearch_title">
        <xsl:attribute name="href">
            <xsl:if test="$mobileRequest">
                <xsl:attribute name="href">
                <!-- Pick only ONE of these -->
                    <!-- Use this one for .aspx URLs -->
                    <xsl:value-of select="concat(substring-before($niceURL, '.aspx'), '/mobile', '.aspx')" />
    
                    <!-- Use this one for DirectoryURLs with no trailing slash -->
                    <xsl:value-of select="concat($niceURL, '/mobile')" />
    
                    <!-- Use this one for DirectoryURLs with a trailing slash -->
                    <xsl:value-of select="concat($niceURL, 'mobile/')" />
                </xsl:attribute>
            </xsl:if>
        <xsl:value-of select="@nodeName" />
    </a>

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft