Showing posts with label razor. Show all posts
Showing posts with label razor. Show all posts

Wednesday, 12 February 2014

Umbraco render macro within macro

I wrote this helper method to easily render macros within other macros when using razor (cshtml) views. This also allows the passing in of parameters. This is an alternative to RenderMacroContent which didn't seem to work for me.

public static string RenderMacro(string alias, int nodeId, Dictionary<string string=> parameters)
        {
            var macroEngine = new RazorMacroEngine();
            var macro = new MacroModel();
            macro.ScriptLanguage = "cshtml";
            macro.ScriptName = alias + ".cshtml";

            foreach (var parameter in parameters)
            {
                macro.Properties.Add(new MacroPropertyModel(parameter.Key, parameter.Value));
            }

            return macroEngine.Execute(macro, new umbraco.NodeFactory.Node(nodeId));
        }


This is the code that wasn't working:

umbraco.library.RenderMacroContent(string.Format("</?UMBRACO_MACRO>", alias, args), model.Id)

Wednesday, 23 January 2013

Umbraco drop down list prevalues using razor

Here is a great link that converts the drop down list datatype prevalues into a Dictionary. Hope this helps someone else out there:

http://blog.dampee.be/post/2012/04/15/Get-a-prevalues-dropdownlist-in-Razor-(umbraco)-for-a-datatype.aspx