Middleman Blog: Custom layout not loading - ruby

In Middleman, I am trying to set up a blog site, using custom layout for the blog. My problem is that the main layout is loading, but the blog layout for my articles is not. The article files are being served in with their plain body.
In source/layouts/ I have two files: layout.erb and article_layout.erb.
My intent is to use article_layout.erb for my blog articles.
In config.rb I have the following:
activate :blog do |blog|
blog.sources = "articles/{category}/{year}-{month}-{day}-{title}.html"
blog.layout = "article_layout"
end
I have also tried moving article_layout.erb to source/articles/ as well as prepending the config.rb file like this: blog.layout = "layouts/article_layout"
Another failed approach is to comment out the above option and configure the layout by adding this line instead: page "/articles/*", layout: "article_layout".
So far none of these approach show a difference. Since the default layout is not being rendered I would expect some sort of error message if the path to the layout cannot be found, but nothing shows up.

I managed to replicate your problem with my own Middleman blog setup.
The docs are unclear on this because there is a broken link in the layout section of Blogging.
You need to use the nested layout feature of Middleman and wrap your custom layout in:
<% wrap_layout :layout do %>
<% end %>
So your article_layout.erb would look something like this:
<% wrap_layout :layout do %>
<div class="article-container">
<article>
<h2 class="article-title"><%= current_page.title %></h2>
<%= yield %>
</article>
</div>
<% end %>
And keep your custom layout in the source/layouts folder.
Here are the docs for Nested Layouts for your reference.
I hope this helps.

Related

Phoenix different title per page with root module

This question is similar to (but not an exact duplicate of) Phoenix Framework - page titles per route.
Ideally, i want to create titles like in the described question, but I am using a root layout since my project uses Phoenix LiveView. The HTML skeleton including the head and title HTML tag are part of the root template (root.html.eex). The app template extends on that from my understanding. I implemented the code from the above question
<title>
<%= if Kernel.function_exported?(#view_module, :title, 2) do %>
<%= #view_module.title(Phoenix.Controller.action_name(#conn), assigns) %> - StHub
<% else %>
StHub
<% end %>
</title>
and created a title function inside of my specific page view
defmodule StHubWeb.WowsView do
use StHubWeb, :view
def title(_action, _assigns) do
"Dashboard"
end
end
but the else branch of the code is triggered. Upon further inspection, I think that the issue is with using a root template, because the #view_module while rendering the root template is StHubWeb.LayoutView, and only inside of the LayoutView/app.html.eex template, the #view_module is my actual view (StHubWeb.WowsView).
I am not sure how to solve this other than removing the root template, but then my LiveView will have to contain the entire HTML skeleton all the time.
Maybe there is a way for me to define a title function in my LayoutView that will grab the title from StHubWeb.WowsView, but I am not sure how to do that.
Thanks for the help!

How do I display content from a Wiki page in another page in redmine?

I'm trying to display content from one wiki page in redmine in my welcome/index file.
I've tried linking pages with [[foo]] (which I have found out only works in the wiki itself) and !{{include(projectname:stuff)}}, but when I try to use this, my redmine only displays it as plain text.
<div class="splitcontentright">
<div class="news box">
<h3><%=("News")%></h3>
!{{include(MyWikiPage:MyArticle))}}
<%= call_hook(:view_welcome_index_right, :projects => #projects) %>
</div>
</div>
Is this the wrong method? Is there another way to achieve what I'm trying to do?
After skimming trough redmines code I found the solution.
Instead of writing
!{{include(MyWikiPage:MyArticle)}}
you'll have to write:
<%= textilizable "{{include(Project:Article)}}" %>
this calls the textilizable function which let's you use wiki macros from wherever you want.

Middleman: How can I get the current article title?

When generating a simple blog in Middleman using the "middleman-blog" extension I get a the layout file which simply yields the content of the post.
What I want is to get the title of the current post and display that.
What I have right now:
<% blog.articles.each do |article| %>
<%= link_to article.title, article %>
<% end %>
This loops through every post title even though only the single post content is displayed. So it outputs something like this for the url /post-title-one
Post Title One Post Title Two Post Title Three
"only the content of post title one"
I want to try something like
<% blog.articles.each do |article| %>
<%= link_to current_article.title, article %>
<% end %>
But it just randomly spits out two page titles.
If you want to print the current article's title just use <%= current_article.title %>.
I'm not quite sure what you're asking. The first block of code you gave is intended to iterate through each article in the blog and generate a link where the link text is the article's title and the target is the article. I would assume that you want to simply link to the current article, since you're on its content page.
<%= link_to current_article.title, current_article %>
That should get the job done.

What does <%anything%> do?

In Rails tutorials and vids, it seems totally different from regular ruby. For example, I see <%render%> or <%end%>. When am I supposed to use <%%> and what is it for?
<% code %> is used in erb, which stands for "Embedded Ruby". It's typically used in HTML generating templates. It's brother is <%= code %> which outputs the return value of the expression inside it.
<h1>Hello, <%= #user.name %>!</h1>
# potentially renders: <h1>Hello, Bob</h1>
# potentially renders: <h1>Hello, Sue</h1>
The non-outputting <% code %> version of this tag is useful for executing code, but not writing anything to the template. This is useful for conditionals (as well as other things).
<h1>
Hello
<% if #user.sex == 'male' %>
Mister
<% else %>
Miss
<% end %>
<%= #user.name %>!
</h1>
# potentially renders: <h1>Hello Mister Bob!</h1>
# potentially renders: <h1>Hello Miss Sue!</h1>
In pure ruby, this would be a syntax error. But within an erb template, these tags allow you to control how the template renders by executing ruby to control the template flow, and by writing out the result of ruby expressions.
Rails uses erb by default for it's views, which are mostly html generating templates. So you see this a lot in Rails examples. Just keep in mind that erb is just one option for your templates in Rails. There is a great many options, which may use different syntax entirely.
That is used in HTML code to display ruby code inside the tags.
<%= render 'folder/partial_form' %>
That will render a form partial.
I suggest you have a nice long read through the links below:
http://www.guides.rubyonrails.org
http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials
The <%= %> and <% %> syntax is used to write ruby in a .erb file. Think of ERB as an html file that always allows ruby code to be run. The <% %> syntax runs the ruby but does nothing by default while the <%= %> syntax(notice the =) outputs the result of the ruby code to the screen.

Frontmatter in Padrino

In Middleman, there is a feature called frontmatter. Basically, you can put some YAML in front of your view and access it in the view and the layout like this:
---
my_list:
- one
- two
- three
---
<h1>List</h1>
<ol>
<% current_page.data.my_list.each do |f| %>
<li><%= f %></li>
<% end %>
</ol>
Is there a similar thing in Padrino?
Such feature does not come with padrino, where you usually would let these values be filled by your controllers.
Depending on your use case, you might use the content_for output helper (http://www.padrinorb.com/guides/application-helpers).
This might help if e.g. want to define the title (as in html/head/title) -- which is usually set by the layout template -- in the "nested" template of your page.

Resources