A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.umbraco.com/umbraco-cms/13.latest/reference/templating/macros/managing-macros below:

Managing macros | Umbraco CMS

Managing macros | Umbraco CMS
  1. Reference
  2. Templating
  3. Macros
Managing macros

In this article you can learn how to create and update a Macro, as well as how to configure its parameters.

There are a couple of ways to create a macro.

The first way is to manually create a macro, by right-clicking the Macro folder in the Settings section:

Create macro

Give it a name in the dialog screen, and you'll be presented with the macro editor.

The second option is to create the macro through Partial View Macro Files.

Partial View Macro files dialog

The dialog provides the following options:

The macro editor view comes with a set of configuration options.

Macro editor

Associate the macro with a partial view. This will already have been configured if you created the macro through the second option described above, where a Partial view was created along with the macro.

Use in rich text editor and the grid

If selected will allow an editor to insert this macro in to a Rich Text Editor and/or into a Grid editor.

Cache period

Defines how many seconds the macro output will be cached for once it is rendered

Cache by page

If selected, then the macro will be cached based on the current page it is rendered on. This is useful if your macro has content that is dynamic to the current page it is being rendered on. If your macro's output is static (the same) no matter what page it is rendered on then it is better to not check this box.

Cache personalized

Similar to the 'Cache by page', this will cache the output of a macro based on a member that is logged in. If your macro is static (the same) no matter what member is logged in, or if your website does not have membership then it is better to not check this box.

Macro parameters can be used to change the output of a macro at runtime. Macro parameters are often used as a way for your editors to change the output of a macro when they insert them into rich text editors. As an example, suppose you have a widget that displays a list of links which are children of a particular content item. You could define a macro parameter that indicates for which content item to render child links for and your editor can select this content item when inserting the macro into the rich text editor.

The macro parameter dialog looks like this:

Macro editor

Here you can add/modify/remove macro parameters.

Default macro parameter types

This list defines the different types of macro parameters:

In some case you want to have the macro in the middle of a sentence.

Inline macros used multiple places inside a single Rich Text Editor

To enable editors to add the macro inline, follow these steps:

  1. Add a macro parameter called: enableInlineMacro.

  2. Choose Checkbox (Umbraco.TrueFalse) as the type.

The next time you add the macro, enable the new parameter to add the macro inline.

Enable Inline Macro by default on a macro

In some cases, you want to have a checkbox that is enabled by default. This would enable you to create your own type of macro parameter that has 1 as the default value. To achieve this, create a DataEditor class anywhere in your Umbraco Project with the following definition:

    [DataEditor(
        alias: "enableInlineMacro",
        type: EditorType.MacroParameter,
        name: "Enable Inline Macro",
        view: "boolean",
        Group = "Macro Config",
        Icon = "icon-list")]
    public class EnableInlineMacro : DataEditor
    {
        public EnableInlineMacro(IDataValueEditorFactory dataValueEditorFactory)
            : base(dataValueEditorFactory)
        {
            DefaultConfiguration.Add("default", "1");
        }
    }

You can create a MacroParameter however you want, the importance is to have a parameter called enableInlineMacro with the value 1 to enable it.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4