Copied to clipboard

Flag this post as spam?

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


  • hetaurhet 245 posts 267 karma points
    Sep 29, 2011 @ 13:27
    hetaurhet
    0

    Master and sub Templates

    hello

    say I have MasterTemplate and created ChildTemplate under it.

    In master doc type there is property name title.

    Now my requirement is if page is created from MasterTemplate then it should take title tag as follows:

    <title><umbraco:Item field="title" runat="server"></umbraco:Item></title>

    and if page is created from ChildTemplate then it should take title as follows: (i.e. override above title tag)

    <title><umbraco:Item field="title" runat="server"></umbraco:Item> | <%=HttpContext.Current.Request["category"]%> | <%=HttpContext.Current.Request["searchtext"]%> | <%=HttpContext.Current.Request["page"]%></title>

    How can I do that?

     


  • Rodion Novoselov 694 posts 859 karma points
    Sep 29, 2011 @ 13:51
    Rodion Novoselov
    0

    It can be done the same way as in any regular ASP.NET application.

    Define some separate placeholder for title, e.g. in the master template and give them default content (in your case i will be a field control):

    <title>
      <asp:ContentPlaceHolder runat="server" ID="phTitle">
          <umbraco:Item field="title" runat="server"/>
      </asp:ContentPlaceHolder>
    <
    /title>

    and give this content placeholder another content in the child template:

    <asp:Content runat="server" ContentPlaceHolderID="phTitle">
      <umbraco:Item field="title" runat="server"/>
          <%=HttpContext.Current.Request["category"]%>
          
    <%=HttpContext.Current.Request["searchtext"]%>
          
    <%=HttpContext.Current.Request["page"]%>

    </asp:Content> 

     

    Actually, it seems that you want to show some kind of a 'breadcrumb' in the tittle of the page, so probably it could be easier just to create a macro for it and to use it in the top-level template.

     

  • hetaurhet 245 posts 267 karma points
    Sep 29, 2011 @ 18:30
    hetaurhet
    0

    thank you.. I will check out

  • hetaurhet 245 posts 267 karma points
    Sep 30, 2011 @ 17:05
    hetaurhet
    0

    hey .. that works.. But  Iwant to modify the same a bit. I want to check querystring param to be null. If null then dont want to append that in title.

  • Rodion Novoselov 694 posts 859 karma points
    Sep 30, 2011 @ 17:30
    Rodion Novoselov
    0

    Very simple:

    <asp:Content runat="server" ContentPlaceHolderID="phTitle">
      <umbraco:Item field="title" runat="server"/>
          <%= (Request.QueryString.Count > 0)? 
                         "|" +   HttpContext.Current.Request["category"]
                     + "|" + HttpContext.Current.Request["searchtext"]
                     + "|" +  HttpContext.Current.Request["page"]             : string.Empty %>
    </asp:Content> 
  • hetaurhet 245 posts 267 karma points
    Sep 30, 2011 @ 18:24
    hetaurhet
    0

    hey thanks ....

    similarly can I access dropdown list value ? this control is on my page.. .say I want to append drplang.selectedValue.

  • Rodion Novoselov 694 posts 859 karma points
    Sep 30, 2011 @ 20:06
    Rodion Novoselov
    0

    Sure, you can insert any valid statement that returns some value between <%= and %> and the result of its calculation will be rendered there.

  • hetaurhet 245 posts 267 karma points
    Oct 01, 2011 @ 06:59
    hetaurhet
    0

    can you give me one example please ....

  • Rodion Novoselov 694 posts 859 karma points
    Oct 03, 2011 @ 07:26
    Rodion Novoselov
    0

    Here's the simplest sample:

    <%= drplang.selectedValue %>

    And here's some details about '<% %>' blocks on MSDN:

    http://msdn.microsoft.com/en-us/library/k6xeyd4z.aspx


  • hetaurhet 245 posts 267 karma points
    Oct 07, 2011 @ 15:40
    hetaurhet
    0

    hey ... its not working... It is giving error: The name 'drplang' does not exist in the current context  ... following is the code in sub-template

    <%@ Master Language="C#" MasterPageFile="~/masterpages/Master.master" AutoEventWireup="true" %>

    <asp:Content runat="server" ContentPlaceHolderID="phTitle"><%= drplang.selectedValue %><umbraco:Item field="title" runat="server"></umbraco:Item><%=(Request.QueryString.Count > 0)?
        " - " + (HttpContext.Current.Request["lang"]== null ? string.Empty : HttpContext.Current.Request["lang"]+" ")
    </asp:Content

     


  • Rodion Novoselov 694 posts 859 karma points
    Oct 07, 2011 @ 15:46
    Rodion Novoselov
    0

    Oh, defenitely it's supposed that you should have a DropDownList control with the ID = drplang somewhere in the same template.

  • hetaurhet 245 posts 267 karma points
    Oct 07, 2011 @ 16:01
    hetaurhet
    0

    actually on this template I have macro which is of .ascx file and this .ascx has drplang dropdown. So, now can you help me how can I access its value?

  • Rodion Novoselov 694 posts 859 karma points
    Oct 07, 2011 @ 17:27
    Rodion Novoselov
    0

    I think, you can try to assign some ID to the Macro control and to find the dropdown with the 'Find' method.

    <%= ((DropDownList)myMacro.Find("drplang")).SelectedValue %>

    ....

    bla-bla-bla

    ......

    <umbraco:Macro ID="myMacro" runat="server" ..... />

  • hetaurhet 245 posts 267 karma points
    Oct 08, 2011 @ 07:27
    hetaurhet
    0

    Actually on document type I have macro container in which I select macro whichever I need on the page. So, how can I proceed now?

    I tried this <%= ((DropDownList)this.FindControl("drplang")).SelectedValue %> ... then it shows

    Object reference not set to an instance of an object.

  • Rodion Novoselov 694 posts 859 karma points
    Oct 08, 2011 @ 10:26
    Rodion Novoselov
    0

    Ok, so I think it'll be more correct to go another way.

    What does this drop-down list do? (Definitely it has to do something - like changing some property of something, or setting a coockie or something like this). Since that you can extract the value in need from the result of what the drop-down does.

    Actually, in Umbraco a macro is supposed to be like 'the thing in itself' and  there's nothing a standard way of making macros communicate each other. Probably it would be great to have such a thing as a part of Umbraco framework - something like 'connected properties' in the WebParts framework, but by now there's still nothing like this.

Please Sign in or register to post replies

Write your reply to:

Draft