MarkdownRecord Docs

ERB Syntax and View Helpers

This section describes how to use ERB syntax and view helpers in your markdown files and ERB views in conjunction with MarkdownRecord models to make navigating across all your rendered content easy.

ERB Syntax

MarkdownRecord supports the use of ERB syntax in your markdown source files. It also provides the following local variables for use in your ERB code:

Rails View Helpers

All the standard view helpers that come with Rails should be accessible within your markdown source files when rendered as ERB files, such as tag helpers and path helpers.

For example, the image below is rendered using the image_tag tag helper:

MarkdownRecord models can also be passed to dom_id for use in Turbo-frames, etc:

<%= dom_id(fragment) %>

View Helpers

MarkdownRecord provides the following view helpers to use in your ERB views as well as in your markdown content source files:

Breadcrumbs

Using the view helpers in conjunction with content fragments, you can easily build navigation that automatically updates when you rerender your content. This guide uses this technique and you can find the following code in the _global_layout.html.erb layout:

<% fragment.parents_from("content/home").each_with_index do |frag, index| %>
    <% unless index == 0%>
        <span class="breadcrumb_divider">/</span>
    <% end %>
    <li><%= link_to_markdown_record(frag) %>
<% end %>

The above content was rendered from source files at: content/v_0_1/erb_syntax_and_view_helpers