Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Feb 10, 2010 @ 13:33
    Dan
    0

    Only display div in template when no querystring present

    Hi,

    I have a website homepage which contains a div containing general content and a list of news items which are paginated.  I want to display the general content div only when the user is on the first page i.e. when there's no querystring variable or when the querystring is 'page=1'.

    Is it possible to insert some inline C# to do this, or is there a better way?

    The code I have in the template is currently like this:

    <asp:content ContentPlaceHolderId="childContent" runat="server">
    <div class="general-content">
    General content
    </div>
    <umbraco:Macro Alias="paginatedArticles" runat="server"></umbraco:Macro>
    </asp:content>

    Thanks for any pointers...

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 10, 2010 @ 13:43
    Dirk De Grave
    4

    Hi Dan,

     

    <asp:content ContentPlaceHolderId="childContent" runat="server">
    <% if (!(string.IsNullOrEmpty(Request.QueryString["page"]))) { %>
           
    <div class="general-content">
                    General content
           
    </div> <% } %>
           
    <umbraco:Macro Alias="paginatedArticles" runat="server"></umbraco:Macro>
    </asp:content>

    Hope this helps.

    Regards,

    /Dirk

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 10, 2010 @ 13:53
    Thomas Höhler
    3

    In XSLT it is:

    <xsl:variable name="year" select="umbraco.library:RequestQueryString('page')"/>
    <xsl:if test="$year != ''">
    <div...

     

  • Dan 1288 posts 3921 karma points c-trib
    Feb 10, 2010 @ 14:03
    Dan
    0

    Thanks Dirk & Thomas.

    Dirk, your solution works when there's no variable, but I also need it to work when the querystring value is 1.  I've tried this, but just get an error:

    <% if ((string.IsNullOrEmpty(Request.QueryString["page"])) || (Request.QueryString["page"].ToString() != '1')){ %>

    The error is something to do with the data types of the requested string and the comparitor:

    "CS0019: Operator '!=' cannot be applied to operands of type 'string' and 'char'"

    Can you see why this is erroring?


  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 10, 2010 @ 14:10
    Thomas Höhler
    0

    '1' is a character not an string so you have to cast:

    if ((string.IsNullOrEmpty(Request.QueryString["page"])) || (Request.QueryString["page"] != '1'.ToString()))

    hth, Thomas

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 10, 2010 @ 14:10
    Thomas Höhler
    0

    btw: the

    Request.QueryString["page"]

    so you dont need to cast this ;-)

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 10, 2010 @ 14:21
    Dirk De Grave
    3

    Or just use "1" instead of '1'.ToString()

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 10, 2010 @ 14:38
    Thomas Höhler
    0

    And again learned a small detail...

    never thought about this...

    thx Dirk

Please Sign in or register to post replies

Write your reply to:

Draft