Copied to clipboard

Flag this post as spam?

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


  • Petr Snobelt 923 posts 1535 karma points
    Apr 03, 2009 @ 22:49
    Petr Snobelt
    0

    Using own extension in template's C# code [solved]

    Hello,

    how can I use my own template from c# code in template?
    I try MyExtension.myMethod() but it dosn't work.

    Petr

  • Richard Soeteman 4054 posts 12927 karma points MVP 3x
    Apr 03, 2009 @ 23:17
    Richard Soeteman
    0

    Hi Petr,

    DId that the other day by creating a class

    [code]

    namespace CustomUmbracoFuntionality.XSLTExtensions
    {
    public class SomeExtension
    {
    ///


    /// Returns the root for the current site
    ///

    public static string GetFullUrl(int nodeId)
    {
    return SomeHelper.GetFullUrl(nodeId);
    }
    }
    }
    [/code]

    Then I modified the XsltExtensions.Config file

    [code][/code]

    Then you can use it in your XSLT using [code]Alias:Method[/code] With 4.0.1 XSLTExtensions declarations are automaticly added to the XSLT in 4.0 you have to do that manually

    [code]

    ]>

    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:SomeExtension="urn:SomeExtension"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library SomeExtension">








    [/code]

    BTW You need a Macro for this.

  • Petr Snobelt 923 posts 1535 karma points
    Apr 03, 2009 @ 23:40
    Petr Snobelt
    0

    Hi Richard,

    Thank you, I allready know how to use extensions from xslt,
    but in v4 I don't need macro, I can use this code in my template directly.

    [code]
    <%@ Import Namespace="MyExtensionNamespace" %>

    <script runat="server"><br />
    MyExtension.MyMethod()<br />
    </script>

    [/code]

    And it works :-)

    Petr

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies