Copied to clipboard

Flag this post as spam?

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


  • Michael Jensen 29 posts 98 karma points
    Dec 28, 2016 @ 11:15
    Michael Jensen
    0

    Make macro work i V7

    Hey,

    i have a webpage iam about to move from V6 to V7 and i have a problem getting my macro to work, it is a cshtml and i must say i dont know howe to get it over in XSLT.

    i hope som can help me.

    my macro is.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    
    @* Ensure that the Current Page has children, where the property umbracoNaviHide is not True *@
    @if (Model.Children.Where("Visible").Any())
    {
        <ul>            
            @* For each child page under the root node, where the property umbracoNaviHide is not True *@
            @foreach (var childPage in Model.Children.Where("Visible"))
            {
                <li class="CleanURl">
                    <div id="ServiceMacroWrapper">
                        <div id="ServiceMacroImageDiv">
                        <a href="@childPage.Url"><img class="ServiceMacroImage" src="@childPage.image"  /></a>
                        </div>
                        <div id="ServiceMacroTextDiv">
                            <div class="ServiceMacroText">
                                @(Library.Truncate(Library.StripHtml(childPage.bodyText), 200, true))
                            </div>
                            <div><a class="readmore" href="@childPage.Url">Læs mere &#8594;</a></div>
                        </div>
                    </div>  
                </li>
            }
        </ul>
    }
    
  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 28, 2016 @ 11:45
    Dave Woestenborghs
    0

    Hi Michael,

    Can't see what is wrong on first sight.

    Maybe you can comment everything and add things bit by bit untill it breaks again. Then we can find the offending line in the code.

    Dave

  • Michael Jensen 29 posts 98 karma points
    Dec 28, 2016 @ 14:49
    Michael Jensen
    0

    Hey Dave,

    i try this combo, my problem is the text part i can't get to work it show´s up link on img.

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
        <xsl:stylesheet 
            version="1.0" 
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
            xmlns:msxml="urn:schemas-microsoft-com:xslt" 
            xmlns:umbraco.library="urn:umbraco.library" xmlns:Examine="urn:Examine" 
            exclude-result-prefixes="msxml umbraco.library Examine ">
    
        <xsl:output method="xml" omit-xml-declaration="yes"/>
    
        <xsl:param name="currentPage"/>
    
        <xsl:template match="/">
    
        <!-- The fun starts here -->
        <ul>
        <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
            <li class="CleanURl">
                        <div id="ServiceMacroWrapper">
                            <div id="ServiceMacroImageDiv">
                            <a href="@childPage.Url"><img class="ServiceMacroImage" src="@childPage.image"  /></a>
                            </div>
                            <div id="ServiceMacroTextDiv">
                                <div class="ServiceMacroText">
                                    @(Library.Truncate(Library.StripHtml(childPage.bodyText), 200, true))
                                </div>
                                <div><a class="readmore" href="@childPage.Url">Læs mere &#8594;</a></div>
                            </div>
                        </div>  
                    </li>
        </xsl:for-each>
        </ul>
    
        </xsl:template>
    
    </xsl:stylesheet>
    

    enter image description here

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Dec 29, 2016 @ 11:17
    Dave Woestenborghs
    0

    Hi Michael,

    The "@Library.Truncate" is razor syntax. XSLT will output this text as is.

    I think there are some equivalents for those methods in xslt but it has been ages since I last wrote a xslt macro in Umbraco.

    The docs for writing xslt macro's can be found here : https://our.umbraco.org/documentation/reference/templating/macros/xslt/

    Unfortunately the part about the Umbraco Library is not documented.

    The functions available can be found in this source file : https://github.com/umbraco/Umbraco-CMS/blob/5397f2c53acbdeb0805e1fe39fda938f571d295a/src/Umbraco.Web/umbraco.presentation/library.cs

    I gave it a try but can not promise if it will work :

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet 
        version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:msxml="urn:schemas-microsoft-com:xslt" 
        xmlns:umbraco.library="urn:umbraco.library" xmlns:Examine="urn:Examine" 
        exclude-result-prefixes="msxml umbraco.library Examine ">
    
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    
    <xsl:param name="currentPage"/>
    
    <xsl:template match="/">
    
    <!-- The fun starts here -->    
    <ul>
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
        <li class="CleanURl">
                    <div id="ServiceMacroWrapper">
                        <div id="ServiceMacroImageDiv">
                        <a href="{umbraco.library.NiceUrl(@id)}"><img class="ServiceMacroImage" src="{current()/image}"  /></a>
                        </div>
                        <div id="ServiceMacroTextDiv">
                            <div class="ServiceMacroText">
                                {umbraco.library.TruncateString(umbraco.library.StripHtml(current()/bodyText),200,'...')}
                            </div>
                            <div><a class="readmore" href="{umbraco.library.NiceUrl(@id)}">Læs mere &#8594;</a></div>
                        </div>
                    </div>  
                </li>
    </xsl:for-each>
    </ul>
    
    </xsl:template>
    

    Personally I would have tried to fix the razor macro. But XSLT is going to be deprecated in future versions of Umbraco.

    Dave

  • Michael Jensen 29 posts 98 karma points
    Jan 02, 2017 @ 18:46
    Michael Jensen
    0

    Thaks for the true Dave,

    my reason to try make it chance was that in v 7 the Scripting files section is no longer and i god confused i normaly make them in that..

    bu i just uploadet the old files and made them work wit a macro..

    Best regards Michael

Please Sign in or register to post replies

Write your reply to:

Draft