Copied to clipboard

Flag this post as spam?

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


  • Robert 63 posts 282 karma points
    Feb 13, 2015 @ 14:16
    Robert
    0

    Pass PageTitle value to Macro

    Hi,

    I have another issue i'm struggling with, how can i pass a PageTitle to a Macro so i can use that for a subject in a mail form?

    I've tried several things but nothing with the result of having the right subject, so i think i'm doing something completely wrong.

    Kind regards, Robert

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 13, 2015 @ 14:19
    Jan Skovgaard
    0

    Hi Robert

    Could you share some examples of the code you have already tried using?

    And is it a certain node in the tree where you're trying to fetch the code from?

    /Jan

  • Robert 63 posts 282 karma points
    Feb 13, 2015 @ 15:29
    Robert
    0

    Hi Jan,

    I have this in the template to load the macro:

    @if(CurrentPage.Where("contactVoorMeerInfo") == true){
    @Umbraco.RenderMacro("NeemContactOp", new {PageSubject = CurrentPage.title})
    }
    

    This is the macro:

    @using System.Collections.Specialized
    

    @using System.Text @using System.Threading @using umbraco.MacroEngines @using System.Net.Mail @inherits DynamicNodeContext

    @{ if ((!IsPost || !ModelState.IsValid)) {

    <form action="" method="post" name="contactForm" target="_self" id="contactForm" class="formular ContactMoreInfoForm form-horizontal" role="form">
        <div class="container ContactMoreInfo">
            <div class="col-md-12 text-center">
                <h2>Meer informatie over?</h2>
                <p>Vul hieronder uw e-mailadres in dan nemen wij z.s.m. contact met u op.</p>
            </div>
            <div class="col-md-2">&nbsp;</div>
                <div class="col-md-8">
                    <input type="text" class="formContact validate[required,custom[onlyLetter]" id="email" name="email" placeholder="E-mailadres" required>
                    <button type="submit" id="SubmitContactForm" class="btnContact">Verzenden</button>
                </div>
            <div class="col-md-2">&nbsp;</div>
        </div>
    </form>
    
    }
    else
    {
    
        string strEmail = Library.StripHtml(Request["email"]).ToString();
    
        var now = DateTime.Now;
        var strTime = String.Format("{0:HH:mm:ss}", now);
        var strDate = String.Format("{0:dd/MM/yyyy}", now);
        var errorMessage = "";
    
        try
        {
    
            var bodyText = "<div style='font-family:arial;font-size:12px;'>" +
                           "<h4 style='padding:8px'>Contact aanvraag</h4>" +
                //PERSOONLIJKE GEGEVENS 
                           "<h5 style='padding:8px'>Gegevens:</h5>" +
                           "<i>E-mailadres:</i> " + strEmail + "<br/>" +
    
                //TIMESTAMP
                           "<strong>Verzonden op:</strong><br/>" + strDate + " " + strTime + "</div>";
    
            using (var client = new SmtpClient("******))
            {
                var mail = new MailMessage();
                mail.From = new MailAddress("[email protected]");
                mail.To.Add("[email protected]");
                mail.Subject = "Meer informatie over: " + Model.MacroParameter["PageSubject"];
                mail.Body = bodyText;
                mail.IsBodyHtml = true;
    
                client.Send(mail);
            }
    
        }
        catch (Exception ex)
        {
            errorMessage = ex.Message;
        }
    
    
        if (errorMessage != "")
        {
    <div id="errorMailSettings">
        <h2>Fout: @errorMessage</h2>
    </div>
        }
        else
        {
    <div class="container ContactMoreInfo">
        <div class="col-md-12 text-center">
            <div id="thankYou">
                <h2>Bedankt!</h2>
                <span class="success">We nemen z.s.m. contact met u op!</span>
            </div>
        </div>
    </div>
    
    <script>
        $("#SubmitContactForm").click(function () {
            $("#contactForm").Validate();
        });
    </script>
        }
        }
    }
    

    I've tried to add this: @inherits Umbraco.Web.Macros.PartialViewMacroPage and load the value with: @Model.MacroParameters[“PageSubject”]

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 13, 2015 @ 16:31
    Jan Skovgaard
    0

    Hi Robert

    So when you add this macro to a RTE field you then enter the Subject parameter, which should be passed to the mail.Subject object?

    And it's this text that is not rendering when the e-mail is sent? Just checking that I get how it's supposed to be working.

    /Jan

  • Robert 63 posts 282 karma points
    Feb 13, 2015 @ 16:52
    Robert
    0

    Hi Jan,

    No, the macro is not added to a RTE, it's loaded into a page template by code. (maybe i don't get you right).

    The PageTitle is already rendered and displayed on the page, on the bottom of that page is 1 field where the visitor can enter his e-mailaddress and click send, i want to have that page title in the subject so that i can see from which page the mail is send and where the visitor wants more info about.

    Kind regards, Robert

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 14, 2015 @ 12:58
    Jan Skovgaard
    0

    Hi Robert

    Ok, what does your code for rendering the macro in the template look like? How do you feed the parameter?

    /Jan

  • Robert 63 posts 282 karma points
    Feb 16, 2015 @ 13:42
    Robert
    0

    Hi Jan,

    This is the code that renders the macro:

    @if(CurrentPage.Where("contactVoorMeerInfo") == true){
        @Umbraco.RenderMacro("NeemContactOp", new {PageSubject = CurrentPage.title})
    }
    

    Regards, Robert

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 16, 2015 @ 14:08
    Jan Skovgaard
    0

    Hi Robert

    Ok - Have you double checked that CurrentPage.Title actually returns anything? If you try rendering it outside the context of the macro call? What happens if you hardcode the page subject? Does it then work?

    /Jan

  • Robert 63 posts 282 karma points
    Feb 16, 2015 @ 14:23
    Robert
    0

    Hi Jan,

    Yes the CurrentPage.Title returns the title on the top of the page, the contact form is on the bottom of that same page. I can put the subject hardcode (it works), but i need to use the same form for all pages on the website, that's why i need to do this dynamically :)

    Regards, Robert

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 16, 2015 @ 14:29
    Jan Skovgaard
    0

    Hi Robert

    Yup, I know that you need to be able to use different page titles depending on where the form is placed. I'm just trying to figure out where things go wrong.

    But now we know that the CurrentPage.Title in fact does hold a value etc.

    Could you try passing the parameter name camelcased? So instead of Model.MacroParameter["PageSubject"] you use Model.MacroParameter["pageSubject"]

    Maye you should also camel-case it where you call the macro.

    I just had a quick glance at the https://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets where it seems it should be camelcased.

    /Jan

  • Robert 63 posts 282 karma points
    Feb 16, 2015 @ 14:30
    Robert
    0

    Hi Jan,

    I've added an image, i think this makes it more clear :)

    enter image description here

  • Robert 63 posts 282 karma points
    Feb 16, 2015 @ 14:31
    Robert
    0

    I was to quick with posting the image hehe :)

    I will try, thanks!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 16, 2015 @ 14:42
    Jan Skovgaard
    0

    Hi Robert

    That's fine - Hope camelcasing is the culprit :)

    /Jan

  • Robert 63 posts 282 karma points
    Feb 16, 2015 @ 14:59
    Robert
    0

    Hi Jan,

    I've tried all the combinations i CamelCase between the template that calls the macro and the macro itself.

    I don't know why this is so difficult, but i can't find any code where the same kind of thing is done, that is working...

    Kind regards, Robert

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 16, 2015 @ 15:04
    Jan Skovgaard
    0

    Hi Robert

    No I'm a bit puzzled as well...Unfortunately I'm out of ideas of what to try out. Don't know if it could be a bug perhaps but then I suspect more people would have been posting about it. Have not checked the issue tracker though...

    EDIT: What exact version of Umbraco are you using btw?

    /Jan

  • Robert 63 posts 282 karma points
    Feb 16, 2015 @ 15:49
    Robert
    0

    Hi Jan,

    I'm using 7.2.1

    /Robert

  • Robert 63 posts 282 karma points
    Feb 19, 2015 @ 10:55
    Robert
    0

    No one else that knows a solution?

  • Robert 63 posts 282 karma points
    Feb 19, 2015 @ 12:42
    Robert
    101

    I fixed it! It's done by using: Model.Name as the subject of the form :)

Please Sign in or register to post replies

Write your reply to:

Draft