I've just created my first and very simple macro; one that gets the current year (to bes used in footer copyrights f.ex.). All that it does is to print @DateTime.Now.Year and I insert it into my rich text editor. Everything works except that there are some forced p tags around it resulting in unwanted line breaks. How can I get around this? Is there a better way to get the year automatically?
Is there a specific reason why you want to insert the macro to your rich text editor?, if not. I would recommend you to add the macro to the templates where the copyright message should be seen, or if you have a master template add the macro in there instead so it shows on every page.
Excuse my late reply. What I want to do is have the footer text (that includes the copyright message) editable but I also want th current year to be updated automatically via a @DateTime.Now.Year. If I put the code into the rich text editor it of course just prints the code instead of giving me the year. What I tried doing was creating a macro that renders an MVC partial view containing the code instead and I then inserted the macro via the rich text editor where I wanted the date to be rendered.
It works as expected but it puts unwanted p tags around it resulting in the text looking like this:
So, is it possible to insert that very simple macro into the rich text editor without having the p tags added around it or is there another and perhaps more correct way to do this? I should mention that I'm new to Umbraco.
Simple year macro
I've just created my first and very simple macro; one that gets the current year (to bes used in footer copyrights f.ex.). All that it does is to print @DateTime.Now.Year and I insert it into my rich text editor. Everything works except that there are some forced p tags around it resulting in unwanted line breaks. How can I get around this? Is there a better way to get the year automatically?
Here's the markup that's being rendered:
<p>Copyright ©</p>
2014
<p> "Company Name"</p>
Hi Peter
What does your code look like? You should probably use @Html.Raw(yourproperty); to disable the character encoding.
See the simple example from sebastiaan here - Please note the example is from 2011 but the @Html.Raw bit should be the same thing you would do today.
Hope this helps.
/Jan
Hi Peter,
Is there a specific reason why you want to insert the macro to your rich text editor?, if not. I would recommend you to add the macro to the templates where the copyright message should be seen, or if you have a master template add the macro in there instead so it shows on every page.
/Dennis
Excuse my late reply. What I want to do is have the footer text (that includes the copyright message) editable but I also want th current year to be updated automatically via a @DateTime.Now.Year. If I put the code into the rich text editor it of course just prints the code instead of giving me the year. What I tried doing was creating a macro that renders an MVC partial view containing the code instead and I then inserted the macro via the rich text editor where I wanted the date to be rendered.
It works as expected but it puts unwanted p tags around it resulting in the text looking like this:
"Copyright ©
2014
Company Name"
instead of just:
"Copyright © 2014 Company Name"
So, is it possible to insert that very simple macro into the rich text editor without having the p tags added around it or is there another and perhaps more correct way to do this? I should mention that I'm new to Umbraco.
is working on a reply...