ryan heath wrote:
This may be a silly question, but I’m wanting to develop a query to pull
‘related articles’ based on tags.
When a user clicks on an article to read, on that layout, I want a side
menu to have the related entries. If I develop the query to do this,
can I access the current tags for the entry in the layout?
I guess I’m asking, does <% content_for_layout %> keep the variables
within that? Or can they be accessed all throughout the page?
If you assign to instance variables in your content, you can access
those in the layout. For example, a content page might contain
<% @title = “Annual Results” %>
and the layout might contain
<%= @title || 'Company Reports' %>
(Here I’ve given a default title ‘Company Reports’ in case @title is
You should be able to do something similar to pass the items for your
side menu from the content to the layout containing the menu.