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.
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?
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 :)
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.
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?
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
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
Hi Jan,
I have this in the template to load the macro:
This is the macro:
@using System.Text @using System.Threading @using umbraco.MacroEngines @using System.Net.Mail @inherits DynamicNodeContext
@{ if ((!IsPost || !ModelState.IsValid)) {
I've tried to add this: @inherits Umbraco.Web.Macros.PartialViewMacroPage and load the value with: @Model.MacroParameters[“PageSubject”]
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
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
Hi Robert
Ok, what does your code for rendering the macro in the template look like? How do you feed the parameter?
/Jan
Hi Jan,
This is the code that renders the macro:
Regards, Robert
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
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
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
Hi Jan,
I've added an image, i think this makes it more clear :)
I was to quick with posting the image hehe :)
I will try, thanks!
Hi Robert
That's fine - Hope camelcasing is the culprit :)
/Jan
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
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
Hi Jan,
I'm using 7.2.1
/Robert
No one else that knows a solution?
I fixed it! It's done by using: Model.Name as the subject of the form :)
is working on a reply...