Copied to clipboard

Flag this post as spam?

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


  • Bob LoCicero 13 posts 32 karma points
    Nov 15, 2011 @ 23:46
    Bob LoCicero
    0

    Wanted: Good, Clear, "Getting Started" with Razor for macros

    Hi,

    I'm having a hard time find a good, clear, step-by-step post on how to get started with creating a Razor macro. I've been plowing through this: http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets

    I feel like this post gives a lot of detailed information that would be helpful to me after I have learned the basics.

    Unfortunately, the posts are over my head at this point: I feel like I'm reverse engineering the information. Razor syntax is clear enough: but the specifics of how create a macro with it are very unclear.

    Also: Is there a library of macros that others have already done? I'm new to this platform and it seems like most of what I need others have probably already developed. I'd prefer to use existing wheels rather than create my own.

    Thanks.

     

  • Justin Spradlin 137 posts 345 karma points
    Nov 16, 2011 @ 04:12
    Justin Spradlin
    2

    I would suggest you start with the Cultiv razor examples. http://our.umbraco.org/projects/developer-tools/cultiv-razor-examples

    It is a complete umbraco install showing how to utilze all the built in data types, plus the uComponents data types and the DAMP media picker. 

    Like everything with umbraco, there are lots of ways to get the job done depending on your requirements. Here are a few of your options when working with razor macros. 

    1. Create a macro on the developer tab for a "razor script". This will create a macro which you can reference from your templates and a cshtml file under the macro scripts section. If you enable the "Visible in UI" option on the macro users can use the rich content editor tool bar to insert a macro. This way you can make a new "TextPage" and add your "Contact Form" macro without having to make a new template for a "Contact Page". This is really helpful if you want to give editors the ability to add macros without letting them alter the templates. 

    2.If you didn't enable the macro to be available in the UI then you will have to add the maro to a template You can add your macro to your template with something like this:

    <umbraco:macro runat="server" alias="myMacroAlias" />

    3. Another quick option I am quite fond of right now is adding the razor script reference directly in my master page with something like

    <umbraco:macro runat="server" fileLocation="~/macroscripts/myrazorscript.cshtml" />
    This method keeps you from having to create a macro just to reference the razor script. 
    I am sure there are other ways out there but these have served me well.
    Justin
Please Sign in or register to post replies

Write your reply to:

Draft