ContentfulElixir.LiveHelpers (ContentfulElixir v0.1.0)

Provides helper functions to render HTML content from Contentful data structures.

This module is designed to transform Contentful's rich text and other complex data types into HTML for display on web pages. It supports a variety of Contentful node types, such as paragraphs, headings, lists, and hyperlinks, converting them into their corresponding HTML tags. This allows for a direct and flexible way to integrate Contentful content into Phoenix LiveView applications or any Elixir-based web rendering context.

The main function, render_content/2, accepts Contentful data as input and returns a string of HTML. It is capable of handling both individual content entries and lists of entries, making it versatile for different types of content structures fetched from Contentful.

Usage

The render_content/2 function can be used within Phoenix templates or LiveViews to dynamically render HTML content based on the data retrieved from Contentful. This simplifies the process of incorporating Contentful's managed content into Elixir applications, providing an easy-to-use interface for content transformation.

Examples

# Rendering a list of content blocks from Contentful
contentful_data = [
  %{"nodeType" => "paragraph", "content" => [%{"nodeType" => "text", "value" => "Hello, world!"}]},
  %{"nodeType" => "heading-1", "content" => [%{"nodeType" => "text", "value" => "Welcome"}]}
]
html_content = ContentfulElixir.LiveHelpers.render_content(contentful_data)
# html_content is now "<p>Hello, world!</p><h1>Welcome</h1>"

This module simplifies the integration of Contentful content into your web application, allowing you to focus on the application logic and user experience while easily managing content through Contentful.

Summary

Functions

Compile elements from contentful direct into html elements

Functions

Link to this function

render_content(data, opts \\ %{})

Compile elements from contentful direct into html elements