How to create a header or footer once and use it on another page

If you make a footer or header, you want to use it for other pages!

Creating a portfolio I found it quite a hassle to recreate the footer and header from scratch every time the page changed, and as soon as I looked it up, it came out so let me share it!

Conclusion

スクリーンショット 2020-10-06 22.08.16.png

This app> layouts> application.html.erb In

application.html.erb


#It has already been described when opened
<!DOCTYPE html>
<html>
  <head>
    <title>PhotoRoke</title>
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>

    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
    <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
  </head>

  <body>
#Describe the header here
    <%= yield %>
#Describe the footer here
</body>
</html>

<%= yield %> Let's write it as if it is sandwiched between the footer and the header!

What is the yield method?

It is a method to expand each template file to the layout template. And that

The layout template is the applocation.html.erb that you edited earlier in Rails. In Rails, that means that different files in other languages may be layout templates.

What the yield method is doing

Very simply yield = HTML on top page yield = HTML for new post page yield = HTML for other pages HTML of each page goes inside in yield like

the end

That's it! Let's do some programming Thank you for visiting!

Recommended Posts

How to create a header or footer once and use it on another page
A memorandum on how to use Eclipse
How to convert a value of a different type and assign it to another variable
Import the instance and use it on another screen
How to make JavaScript work on a specific page
How to convert A to a and a to A using AND and OR in Java
(Ruby on Rails6) How to create models and tables
How to create a method
How to use OpenCV 4 on Android and view camera live view
How to create a placeholder part to use in the IN clause
How to create and launch a Dockerfile for Payara Micro
How to create a Wear OS by Google app project on Android Studio 3.0 or higher
How to add another project as Maven library with CircleCI and use it for build
How to use StringBurrer and Arrays.toString.
How to create a jar file or war file using the jar command
How to install and use Composer on an ECS instance on Ubuntu 16.04
How to use EventBus3 and ThreadMode
How to use Ruby on Rails
How to use equality and equality (how to use equals)
How to use Bio-Formats on Ubuntu 20.04
[Java] How to create a folder
How to read a file and treat it as standard input
How to create a web server on an EC2 instance on AWS
Use Jenkins to build inside Docker and then create a Docker image.
Create a Docker Image for redoc-cli and register it on Docker Hub
Steps to install Maven on Mac and use it in Eclipse
[Rails] How to simply put a link to a static page such as terms of use or privacy policy
Inexperienced create a weather app using OpenWeatherMap and deploy it to Netlify
How to create a query using variables in GraphQL [Using Ruby on Rails]
[Docker] How to create a virtual environment for Rails and Nuxt.js apps
Create a program to post to Slack with GO and make it a container
How to create a server executable JAR and WAR with Spring gradle
[Rails] How to create a table, add a column, and change the column type
How to create a convenient method that utilizes generics and functional interfaces
How to redo a deployment on Heroku
How to use Apache Derby on Eclipse
How to use OrientJS and OrientDB together
How to standardize header footer in Thymeleaf
How to create a Maven repository for 2020
How to set up and use kapt
[Ruby on Rails] How to use redirect_to
[Swift5] How to create a splash screen
[rails] How to create a partial template
[Ruby on Rails] How to use kaminari
How to use substring and substr methods
How to use @Builder and @NoArgsConstructor together
How to ZIP a JAVA CSV file and manage it in a Byte array
[Spring sample code included] How to create a form and how to get multiple records
How to find the distance and angle between two points on a plane
[Introduction to Docker] Create a Docker image for machine learning and use Jupyter notebook
How to use Eclipse on my PC with 32bit and 2GB of memory
Introducing what I made when I wanted to add a header and footer to RecyclerView
How to create a database for H2 Database anywhere
[Java] How to use FileReader class and BufferedReader class
[Ruby] How to use the map method. How to process the value of an object and get it by hash or symbol.
How to deploy a container on AWS Lambda
[Rails] How to create a graph using lazy_high_charts
How to display a web page in Java
[Ruby] How to use gsub method and sub method
How to create pagination for a "kaminari" array
How to create a class that inherits class information