Is it possible using this line here:

<%= partial 'some/catalog/file' %> 

to cause different pieces from the same .erb file?

I do HTML5 statics. It is necessary to make separate files on each page (there are a lot of them), meta tags, I would like to call it all from one .erb file.

I work on middleman3 framework. How can this be implemented? Very many files, so you get confused - what's where.

In order not to be confused with the wording and concepts, I post a screen about my question.

Is it possible?

An example of what I would like to achieve ...

  • Not quite understand the problem, maybe you're looking for a content_for helper? - Vasilisa
  • and what does this helper do - content_for? The task was this, there is one * .erb file and there are different pieces of html in it for different pages, so here’s how to explain where to get what piece of code? there are homogeneous pieces of html for different pages and it is more convenient to edit them in one place than to create a bunch of separate files, right?) - Vision 10
  • if you do this, then it should look something like, in the very * .erb you make some notations / selections (I don’t know what to call it ...) of the html pieces, and then when you call them with the line <% = partial 'some / catalog / file '%> is already clarifying ala <% = partial' some / catalog / file ',' refinement '%> is just a fantasy) and may not work at all) - Vision 10
  • Maybe you should add a specific code to the question? While it looks like you are trying to go the wrong way. If your file contains very different parts of html and they need to be rendered in different places of other views, it will be much more convenient to break it into several separate partials and quietly render them in the right places - Vasilisa
  • Look, added a screenshot of the question with sample code, is it possible to do this? - Vision 10

2 answers 2

in the folder of your project ( layouts ), add files (for example _header.html.erb ) sign

_

generally accepted to indicate that this is part of the main view

and on the main page ( application.html.erb ) where parts of your views will be collected

output through the render

 <%=render 'layouts/header' %> 

Also for speed and html compression you can use this magic thing.

 gem slim-rails 

then the whole code can be replaced by

 = render 'layouts/header' 
  • Thanks, of course ... but not as it did not help much, the essence of the question is how to take different pieces of html from a single * .erb file for different pages. But for gem slim-rails thanks of course) - Vision 10
  • Look, added a screenshot of the question with sample code, is it possible to do this? - Vision 10

It should work through content_for, which I wrote about at the very beginning. In your partial collect all the necessary pieces of code

 # _my_very_big_mixing_up_all_the_stuff_partial.erb <% content_for :contacts do %> <p>Contacts</p> <% end %> <% content_for :banner do %> <p>Banner</p> <% end %> 

Then in the layouts, with the first line, render the partial and invoke the part with the necessary identifier

 # layouts/contacts.erb <%= partial 'partials/my_very_big_mixing_up_all_the_stuff_partial' %> <%= yield_content :contacts %> # layouts/banner.erb <%= partial 'partials/my_very_big_mixing_up_all_the_stuff_partial' %> <%= yield_content :banner %> 
  • Thanks for the answer, it looks like what you need, but I don’t really understand what the view is ... I did not use it ... where does this file render? - Vision 10
  • I tried to render the first line in the page (contact.html.erb) error ... - Vision 10
  • @ Vision10, I just now realized that this is not about rails ... Why did you put the ruby-on-rails tag? I never worked with Middleman, but the dock says that content_for is also there, only it is called differently. The answer is corrected, look. And yes, if you have an error, then it would be nice to put its text on public display too - Vasilisa
  • it seemed that cutting the rails was also similar to cutting ) just a beginner ... did as you wrote, the error is the same, here is the output screen 1- imgur.com/L7NgYgO 2- imgur.com/q823P98 3- imgur.com/NB2OtQW - Vision 10
  • @ Vision10, chop is a language, rails are a framework for rubies, middleman is also a framework for rubies. I once again corrected the answer, for partials, you should use partial instead of render . I'm not sure that I can help you with further debugging - I learned about the existence of Middleman today from your question, so try to bring the idea of ​​content_for to mind with the help of documentation :) - Vasilisa