Copied to clipboard

Flag this post as spam?

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


  • Thanh Tran Huy 22 posts 42 karma points
    Sep 23, 2013 @ 13:38
    Thanh Tran Huy
    0

    Need to help @Umbraco.RenderMacro parameter

    I have code render marco in template aspx as below:

    <umbraco:Macro ID="javascrpt" alias="javascrpt" runat="server" FileLocation="~/macroScripts/scripts.cshtml"/>

    Now, I'm using template cshtml. How to render this macro.

    Please help me!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Sep 23, 2013 @ 14:06
    Jeavon Leopold
    0

    Hi Thanh,

    I'm not sure what your parameter is there, but here is how you can render a Macro from a Mvc view:

    @Umbraco.RenderMacro("myMacroAlias", new { name = "Ned", age = 28 })
    

    More info here

    Jeavon

  • Thanh Tran Huy 22 posts 42 karma points
    Sep 23, 2013 @ 15:08
    Thanh Tran Huy
    0

    Hi Jeavon Leopold!

    Thanks for you help!

    My problem as following:

     - I have file "script.cshtml" in "Scripting Files" folder.

     - I want render this file in template cshtml. 

    Can you hep me!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Sep 23, 2013 @ 15:18
    Jeavon Leopold
    0

    Hi Thanh, are you using a Mvc cshtml template that starts with @inherits Umbraco.Web.Mvc.UmbracoViewPage or @inherits Umbraco.Web.Mvc.UmbracoTemplatePage or are you using a Razor macro in a WebForms .master template where the Razor cshtml would start with @inherits umbraco.MacroEngines.DynamicNodeContext?

  • Thanh Tran Huy 22 posts 42 karma points
    Sep 23, 2013 @ 17:23
    Thanh Tran Huy
    0

    Hi Jeavon Leopold. I'm using MVC cshtml template start with @inherits Umbraco.Web.Mvc.UmbracoTemplatePage

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Sep 23, 2013 @ 17:25
    Jeavon Leopold
    0

    Ok, so I don't understand, why don't you use a partial view rather than trying to use a Macro? Can you post the contents of /macroScripts/scripts.cshtml I'm sure we can convert it to a Partial...?

  • Ali Sheikh Taheri 470 posts 1648 karma points c-trib
    Sep 23, 2013 @ 18:03
    Ali Sheikh Taheri
    0

    try this

    @RenderPage("/macroScripts/scripts.cshtm")
    
  • Thanh Tran Huy 22 posts 42 karma points
    Sep 24, 2013 @ 03:30
    Thanh Tran Huy
    0

    Hi Ali! I have try. It don't work. Thank you!

    Hi Jeavon. That is a good solution for me. Because I got source form old developer. I'm switching from Webform to MVC. Thank you!

    My problem have been solved. This Scripting File doesn't have Macro. I create new Macro and access to Scripting File

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Sep 24, 2013 @ 09:08
    Jeavon Leopold
    0

    Hi Thanh,

    That should work fine, but It would be better to convert the existing file to a partial view. If you post the code I'm sure we can help convert it for you.

    Jeavon

  • Thanh Tran Huy 22 posts 42 karma points
    Sep 24, 2013 @ 10:00
    Thanh Tran Huy
    0

    Hi Jeavon. I have many Scripting Files like this. One of them here:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
    
        var root = Model.NodeById(Model.Path.Split(',')[1]);
    
        var blog = Model.NodeById(Model.Id);
    
        var parentNode = Model.NodeById(blog.parent.Id);
    
    
        // Get blogger
    
        var blogger = Model.NodeById(0);
    
        foreach (var item in root.Descendants("blogger"))
        {
    
            if (item.loginName.ToLower() == blog.creatorName.ToLower())
            {
    
                blogger = item;
    
                break;
    
            }
    
        }
    
        string dns = "http://" + Request.Url.Authority;
    
        var bloggerUrl = dns + "/blogsbyblogger?name=" + blogger.loginName;
    
        var urlRss = dns + "/bloggerrss?name=" + blogger.loginName;
    
        var currentUrl = dns + blog.Url;
    
    
    
        // Get blog social links
    
        var blogSocials = Model.NodeById(root.blogSocialLinks);
    
    
    
        // Get related product
    
        var course = Model.NodeById(0);
    
        // find out if we need low seats stripe   
    
        bool showStrip = false;
    
        if (blog.relatedProduct != "")
        {
    
            course = Model.NodeById(blog.relatedProduct);
    
            foreach (var booking in course.Children)
            {
    
                int seatstotal = booking.seats;
    
                int seatstaken = 0;
    
                foreach (var parti in booking.Children)
                {
    
                    seatstaken = seatstaken + parti.numberOfParticipant;
    
                }
    
                if (seatstotal < booking.Children.Count() + 3)
                {
    
                    showStrip = true;
    
                }
    
            }
    
        }
    
        <div class="contentBlog">
    
            <div class="blogIndlaeg">
    
                <h1>
    
                    @blog.title</h1>
    
                <h6>
    
                    @blog.description</h6>
    
                <div class="dateAndComments">
    
                    <p>
    
                        @blog.createDate.ToString("MM/dd/yyyy") <a href="parentNode.Url">@parentNode.Name</a>
                    </p>
    
                    <p>
                        Tagget med 
    
                        @{
    
                            foreach (var blogTag in @blog.tag.Split(','))
                            {
    
                                string url = dns + "/BlogByTags?tagName=" + @blogTag;
    
                            <a href="@url">@blogTag</a>
    
                            }
    
    
    
                        }
    
                    </p>
    
    
    
                    <p>
    
                        <fb:comments-count href="@currentUrl"></fb:comments-count>
    
                        kommentarer - 
    
                        <a href="#allComment">skriv kommentar</a>
    
                    </p>
    
                    <div class="clear">
                    </div>
    
                </div>
    
                @if (blog.blogImage != "")
                {
    
                    <img src="@blog.Media("blogImage", "umbracoFile")" class="topImage">
    
                }
    
                <div class="mainText">
    
                    @if (blog.relatedProduct != "")
                    {
    
                        <div class="upcoming" onclick="window.location='@(course.Url)'">
    
                            <div class="top">
    
                                @if (!course.splitToMany)
                                {
    
                                    <h1>@course.Name</h1>
    
                                }
    
                                else
                                {
    
                                    <h1>@course.Name</h1>
    
                                }
    
                                @if (!String.IsNullOrEmpty(course.manchet))
                                {
    
                                    <img src="@course.Media("manchet", "umbracoFile")" id="stripe"/>
    
                                }
    
                            </div>
    
                            <div class="text">
    
                                @if (course.body.Length > 80)
                                {
    
                                    <p>@(course.body.Substring(0, 80))...</p>
    
                                }
    
                                else
                                {
    
                                    <p>@course.body</p>
    
                                }
    
                                @if (!String.IsNullOrEmpty(course.callToAction))
                                {
    
                                    <h6>
    
                                        <img src="../../images/orangeSun.png" id="orangeSun" />@course.callToAction</h6>
    
                                }
    
                            </div>
    
                            <div class="textHidden">
    
                                @{
    
                                int hours = 0;
    
    
    
                                // find the longest course
    
                                foreach (var booking in course.Children)
                                {
    
                                    if (booking.endDate >= booking.startdate)
                                    {
    
                                        System.TimeSpan diffResult = booking.endDate.Subtract(booking.startdate);
    
                                        if (hours < diffResult.TotalHours)
                                        {
    
                                            hours = (int)diffResult.TotalHours;
    
                                        }
    
                                    }
    
                                }
    
                                }
    
                                @{
    
                                int varighedVal = 0;
    
                                string varighedTxt = "dag";
    
    
    
                                if (hours < 24)
                                {
    
                                    varighedTxt = "time";
    
                                    varighedVal = hours;
    
    
    
                                    if (varighedVal > 1)
                                    {
    
                                        varighedTxt = "timer";
    
                                    }
    
                                }
    
                                else
                                {
    
                                    varighedVal = (int)(hours / 24.0);
    
    
    
                                    if (varighedVal > 1)
                                    {
    
                                        varighedTxt = "dage";
    
                                    }
    
                                }
    
                                if (varighedVal > 0)
                                {
    
                                    <p>
    
                                        <img src="../../images/grayClock.png" id="grayClock" />Varighed op til @varighedVal @varighedTxt
    
                                    </p>
    
                                }
    
                                }
    
                                <ul>
    
                                    @foreach (var booking in course.Children)
                                    {
    
                                        <li><a href="@(course.Url)[email protected]" style="color: black; text-decoration: none; font: 12px DroidSerif_Reqular,sans-serif !important;">@booking.startdate.ToString("dd/MM yy")</a></li>
    
                                    }
    
                                    <div class="clear">
                                    </div>
    
                                </ul>
    
                            </div>
    
                            <img src="../../images/whiteShadow.png" id="whiteShadow" />
    
                            <button onclick="location.href='@course.Url';">
                                Se kursus
    
                            </button>
    
                        </div>
    
                    }
    
    
    
                    @blog.content
    
                    <div class="clear">
                    </div>
    
                </div>
    
                <ul class="humanRss">
    
                    <li>
    
                        <div class="humanBlock">
    
                            <div class="image">
    
                                <img src="@blogger.Media("photo", "umbracoFile")">
                            </div>
    
                            <div class="name">
    
                                <h1>
    
                                    @blogger.displayName<br>
    
                                    <span>@blogger.occupation</span></h1>
    
                            </div>
    
                            <div class="clear">
                            </div>
    
                        </div>
    
                        <div class="text">
    
                            <p class="paragraph">
    
                                @blogger.introduction
    
                            </p>
    
                            <div class="personalRss" style="margin-top: 20px">
    
                                <p style="margin-top: 0px">
    
                                    <a href="@urlRss">RSS for @blogger.displayName</a>
                                </p>
    
                                <img src="../../images/personalRss.png" style="margin-top: 0px">
    
                                <a class="linkBlogDetail" href="@bloggerUrl" style="margin-left:20px">Se alle indlæg
    
                                </a>
    
                                <div class="clear">
                                </div>
    
                            </div>
    
                        </div>
    
                    </li>
    
                    <li class="noMargin">
    
                        <div class="sotialInfo">
    
                            <h1>Del indlægget med dit netværk</h1>
    
                            <div style="text-align: center;">
    
                                @foreach (var social in blogSocials.Children)
                                {
    
                                    var socialLink = "";
    
                                    if (social.Name.ToLower() == "facebook" || social.Name.ToLower() == "google+")
                                    {
    
                                        socialLink = string.Format(social.link, currentUrl);
    
                                    }
    
                                    else if (social.Name.ToLower() == "twitter" || social.Name.ToLower() == "linkedin")
                                    {
    
                                        socialLink = string.Format(social.link, blog.title, currentUrl);
    
                                    }
    
                                    <a href="@socialLink" target="_blank">
    
                                        <img src="@social.Media("icon", "umbracoFile")"></a>
    
                                }
    
                            </div>
    
                            <p>
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer lacus est, posuere
    
    non iaculis eu, c onvallis quis mi. Morbi at consequat dui suspendisse eu.
    
                            </p>
    
                            <h1>Tak for din hjælp!</h1>
    
                        </div>
    
                    </li>
    
                    <div class="clear">
                    </div>
    
                </ul>
    
                <div id="allComment" class="facebookPlugin">
    
                    <fb:comments href='@currentUrl' num_posts='10' width='700'></fb:comments>
    
                </div>
    
            </div>
    
        </div>
    
    }
    
    <script type="text/javascript">
    
        $(document).ready(function () {
    
            var blogId = '@Model.Id';
    
            $.post('/service.aspx', { m: 'updateBlogCount', blogId: blogId }, function (response) {
    
                if (response.errorcode == '0') {
    
                }
    
            }, 'json');
    
    
    
            upcomingBlock();
    
    
    
        });
        //function upcomingBlock() {
    
        //$(".wrapper .contentBlock .content .contentBlog .blogIndlaeg .mainText div.upcoming").hover(function () {
    
        //$(this).children('.text').fadeOut(0);
    
        //$(this).children('.textHidden').fadeIn(0);
    
        //}, function () {
    
        //$(this).children('.textHidden').fadeOut(0);
    
        //$(this).children('.text').fadeIn(0);
    
        //});
    
        //$('.wrapper .contentBlock .content .contentBlog .blogIndlaeg .mainText div.upcoming .textHidden ul li:nth-child(2n)').css('margin-right', '0px')
    
        //}
    </script>
    
  • Thanh Tran Huy 22 posts 42 karma points
    Sep 24, 2013 @ 10:03
    Thanh Tran Huy
    0

    I have somr problem with Surface Controller and Partial View. Can I post question in this topic?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Sep 24, 2013 @ 18:12
    Jeavon Leopold
    0

    Hi Thanh,

    I have converted the first part for you to consider if it's worth doing it for the whole file

    Main change for conversion is Model.NodeById becomes Umbraco.TypedContent and as I've used Strongly Typed rather than dynamic model you need to use Model.GetPropertyValue

    var root = Umbraco.TypedContent(Model.Path.Split(',')[1]);
    var blog = Umbraco.TypedContent(Model.Id);
    var parentNode = Umbraco.TypedContent(blog.Parent.Id);
    
    // Get blogger
    
    var blogger = Umbraco.TypedContent(0);
    foreach (var item in root.Descendants("blogger"))
    {
        if (item.GetPropertyValue<string>("loginName").ToLower() == blog.GetPropertyValue<string>("creatorName").ToLower())
        {
            blogger = item;
            break;
        }
    }
    
    string dns = "http://" + Request.Url.Authority;
    var bloggerUrl = dns + "/blogsbyblogger?name=" + blogger.GetPropertyValue<string>("loginName");
    var urlRss = dns + "/bloggerrss?name=" + blogger.GetPropertyValue<string>("loginName");
    var currentUrl = dns + blog.Url;
    

    Hope that's helpful to you,

    Jeavon

  • Thanh Tran Huy 22 posts 42 karma points
    Sep 25, 2013 @ 04:39
    Thanh Tran Huy
    0

    Thank you Jeavon!

    This is helpful knowledge.

Please Sign in or register to post replies

Write your reply to:

Draft