Copied to clipboard

Flag this post as spam?

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


  • Peter S 169 posts 587 karma points
    Mar 24, 2014 @ 15:02
    Peter S
    0

    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 &copy;</p>
    2014
    <p> "Company Name"</p>

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Mar 24, 2014 @ 15:10
    Jan Skovgaard
    1

    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

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Mar 24, 2014 @ 15:15
    Dennis Aaen
    0

    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

     

  • Peter S 169 posts 587 karma points
    Mar 25, 2014 @ 07:20
    Peter S
    0

    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.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies