Copied to clipboard

Flag this post as spam?

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


  • Profiterole 232 posts 264 karma points
    Feb 11, 2011 @ 18:52
    Profiterole
    0

    display altTemplate in backend

    Hi guys,

    Normaly, my node has a http://www.server.com/node.aspx url. But, for my "admin" users, I'd like to create in the backend a clickable link to http://www.server.com/node.aspx?altTemplate=Other_template. So, they don't have to remember the syntax, they just have to click from backend. Is it possible? I have a lot of nodes which should work like this, so I must be able to use something like niceurl.

    Thank you

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 11, 2011 @ 18:59
    Tom Fulton
    1

    Hi,

    You'd have to make a custom datatype to do this, but it should be very easy...it won't even need to store any data.

    You can use umbraco.library.NiceUrl to get the URL using the "id" querystring and append "?altTemplate=...." in the usercontrol.

    If you're not familiar with this check out Tim's blog and/or umbraco.tv to get started.  Let us know if any questions...

    -Tom

  • Profiterole 232 posts 264 karma points
    Feb 11, 2011 @ 20:02
    Profiterole
    0

    I never created a custom datatype, I'll read Tim's blog. Thank you

  • Profiterole 232 posts 264 karma points
    Feb 11, 2011 @ 20:19
    Profiterole
    0

    Hi! I don't have Juno and I'm a Linux user... so I can't install visual studio!  No mocking please :) I used to php and "notepad" edition. Is there a way I can do my datatype?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 11, 2011 @ 21:42
    Tom Fulton
    1

    Hi

    Today is your lucky day :)

    - Create the files below and put both in the /usercontrols directory
    - Change "altTemplateAlias" in the second file from "myAltTemplate" to whatever you want
    - Goto Developer -> DataTypes and create a new Datatype
    - Select umbraco usercontrol wrapper as the Render Control
    - Select AltTemplateLink.ascx from the usercontrol dropdown
    - Save
    - Add the new datatype to a doctype

    Oh yeah, and get a Windows machine with Visual Studio :)

     

    AltTemplateLink.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="AltTemplateLink.ascx.cs" Inherits="AltTemplateLink" %>
    <asp:HyperLink ID="lnkAltTemplate" runat="server"></asp:HyperLink>

     

    AltTemplateLink.ascx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using umbraco;
    using umbraco.editorControls;

    public partial class AltTemplateLink : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor 
    {
        string altTemplateAlias = "myAltTemplate";
        string linkText = "Click Me";
       
       
        protected void Page_Load(object sender, EventArgs e)
        {
            int nodeId = int.Parse(HttpContext.Current.Request.QueryString["id"].ToString());

            lnkAltTemplate.Text = linkText;
            lnkAltTemplate.NavigateUrl = umbraco.library.NiceUrl(nodeId) + "?altTemplate=" + altTemplateAlias;
            lnkAltTemplate.Target = "_blank";
        }
       
        private string _umbracoValue;

        public object value {
            get
            {
                return "";
            }
            set
            {
                _umbracoValue = value.ToString();
            }
        }
    }
  • Profiterole 232 posts 264 karma points
    Feb 12, 2011 @ 01:25
    Profiterole
    0

    Wow!! Thanks a lot!! Now I have a better understanding of custom datatype and I now I can do that in notepad!

Please Sign in or register to post replies

Write your reply to:

Draft