Render children node views inside it's parent node view


(Buwaro) #1

Is There a PushType way to render a view of a node inside another node’s view?
I’d like to do this so that an admin can add different parts to a page and order them how they want

For now, I solved the problem by creating a partials for every child node:

app/models/page.rb

class Page < PushType::Node
  has_child_nodes :all
end

app/views/nodes/page.html.erb

<% @node.children.each do |child | %>
  <%= render "nodes/_#{child.class.name}", node: child %>
<% end %>

app/views/nodes/video.html.erb (so that the preview still works)

<%= render "nodes/_video", node: @node %>

app/views/nodes/_video.html.erb

# The html that was in the video view with the variable names changed from '@node' to 'node'
  • other nodes like video for ex: items, photos, …

But maybe it would be easier with something like a render_node() helper?