I'm doing statics on html5. I have many HTML lines of the same type:
<meta name="keywords" content="any keywords" />
<meta name="description" content="any description" />
The site has many pages, and editing these lines takes a lot of time for each individual file *.erb.
I wanted to find out how to call the required string from a single * .erb file. If I use <%= partial '...' %> in this case, the entire file will be called. Tell me if any opportunity to call only those lines which are necessary. I do not know how to call any line parts of a file from one file *.erb using middleman3. Perhaps there is a method to call from a file - lines by numbers, or any method.
===
since i'm a beginner maybe i don't understand
is it possible? look at the picture
Create a new file for instance "views/_partial.html.erb" ; The filename should begin with an underscore. Put your HTML content in this file which is the following:
<meta name="keywords" content="any keywords" />
<meta name="description" content="any description" />
Now from the view from which you want to call the partial, use the following code:
<%= render :partial => 'views/partial' %>
Note: while calling the partial you should exclude the underscore.
Edit Method 2
File: _partial.html.erb
<% if page == 1 %>
<meta name="keywords" content="any keywords" />
<meta name="description" content="any description" />
<% elsif page == 2 %>
<meta name="keywords" content="any keywords" />
<meta name="description" content="any description" />
<% end %>
Code to call the partial
<%= render partial: 'partial', locals: {page: 1} %>
<%= render partial: 'partial', locals: {page: 2} %>
Related
I want to integrate swagger UI into my ruby based slate generated API docs , for that I looked up here
and did the directed changes to the layout.erb file adding the required head and body sections but upon building the webpage nothing shows up , these are the modified head and body section.
<head>
<meta charset="utf-8">
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title><%= current_page.data.title || "API Documentation" %></title>
<link rel="stylesheet" type="text/css" href="swagger-ui.css">
<style>
<%= Rouge::Themes::MonokaiSublime.render(:scope => '.highlight') %>
</style>
<%= stylesheet_link_tag :screen, media: :screen %>
<%= stylesheet_link_tag :print, media: :print %>
<% if current_page.data.search %>
<%= javascript_include_tag "all" %>
<% else %>
<%= javascript_include_tag "all_nosearch" %>
<% end %>
<body class="<%= page_classes %>" data-languages="<%=h language_tabs.map{ |lang| lang.is_a?(Hash) ? lang.keys.first : lang }.to_json %>">
<div id="swagger-ui"></div>
<script src="swagger-ui-bundle.js"></script>
<script src="swagger-ui-standalone-preset.js"></script>
<script>
window.onload = function() {
const ui = SwaggerUIBundle({
url: "https://qa-refapp.openmrs.org/openmrs/module/webservices/rest/swagger.json",
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
]
})
window.ui = ui
}
</script>
I added the complete layout.erb file here
I am working on a rails project and am unable to identify the source of the error : SyntaxError: [stdin]:10:26: missing ) when i render application.html.erb.
From the template i can't find the cause of the error or how to fix it.
Am using Rails 5.1.6
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>App</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= csrf_meta_tags %>
<%= tag :meta, name: :psj, action: action_name, controller: controller_name %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= render 'layouts/header' %>
<%= yield %>
<%= render 'layouts/footer' %>
</body>
</html>
Isolating code sections shows that the error is being triggered by either including the lines containing ** javascript_include_tag ** or stylesheet_link_tag
THis is my first page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="newjstl.jsp" method="post">
FirstName:<input type="text" name="fname"/><br/>
LastName:<input type="text" name="lname"/><br/>
<input type="submit" value="submit"/>
</form>
</body>
</html>
The second page is
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:forEach var='value' items='${paramValues}'>
First Name:<c:out value="${value.fname}"></c:out><br/>
Last Name:<c:out value="${value.lname}"></c:out>
</c:forEach>
It is throwing an exception org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'java.util.HashMap$Entry' does not have the property 'fname'.
I don't know why it is not working.
See http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPIntro7.html#wp71044.
paramValues is the map of parameters. It maps parameter names (the keys of the map) to their values (array of String).
You're iterating over this map. The forEach loop thus iterates over the entries of the map, which are of type Map.Entry<String, String[]>. And Map.Entry doesn't have any getFname() method.
What you actually want is
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
First Name:<c:out value="${param.fname}" /><br/>
Last Name:<c:out value="${param.lname}" />
There's no reason to loop, and you simply want to get the single value of a given parameter. That'w what param is for.
JB Nizet has it correctly.
Assume that 'fname' was set to "George", and 'lname' was set to "Smith" in 'first page'.
'paramValues' is a HashMap, so when you use it in 'forEach', what you're getting in 'value' is a Map.Entry, and Map.Entry doesn't have a 'fname' field, so there's no 'getFname' method for JSP to call.
If you insist, 'value' can be used as '${value.key}' and '${value.value}', but that will get you the pairs :
'fname', "George"
'lname', "Smith"
respectively. I doubt that's what you want. The only reason to use a 'forEach' would be if you were expecting multiple answers and needed to iterate through all of them. That's not what's been given as the example.
The following was copied from Implicit Objects, and shows pretty much what I suggest above.
<%-- For every String[] item of paramValues... --%>
<c:forEach var='parameter' items='${paramValues}'>
<ul>
<%-- Show the key, which is the request parameter
name --%>
<li><b><c:out value='${parameter.key}'/></b>:</li>
<%-- Iterate over the values -- a String[] --
associated with this request parameter --%>
<c:forEach var='value' items='${parameter.value}'>
<%-- Show the String value --%>
<c:out value='${value}'/>
</c:forEach>
</ul>
</c:forEach>
To pass parameters to a jsp jstl:
/* JSP PARENT */
<jsp:include page="../../templates/options.jsp">
<jsp:param name="action" value="${myValue}"/>
</jsp:include>
/* JSP CHILD (options.jsp)*/
<div id="optionButtons left">
<span>${param.action}</span>
</div>
Because the fields in your form aren't named the same, you can't use 'forEach' tag. I think this will work!
First Name:${param.fname}
Last Name:${param.lname}
I am trying to do something like this in an aspx page:
<head runat="server">
<% #if DEBUG %>
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<% #else %>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<% #endif %>
</head>
I get an error "Preprocessor directives must appear as the first non-whitespace character on a line". How can I do this?
<head runat="server">
<%
#if DEBUG
%>
<script src="jquery-1.3.2.js" type="text/javascript"></script>
<%
#else
%>
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<%
#endif
%>
</head>
Works for me - note that this is based on the value of the debug attribute in the <compilation> element of the web.config.
Edit to respond to comment
Ah, so you're also adding controls to the head through the code-behind? Then you'll probably need to be adding this dynamically from the code-behind as well.
If you're happy to always serve the minified version, but want to use IntelliSense in Visual Studio you should ensure that you've installed the hotfix to enable this:
VS2008 SP1 Hotfix to Support "-vsdoc.js" IntelliSense Doc Files
This would enable you to name your non-minified version jquery-1.3.2.min-vsdoc.js and have VS read that one in while you're building the pages.
this is worked for me:
<head runat="server">
<asp:PlaceHolder runat="server">
<%
#if !DEBUG
%>
<meta http-equiv="X-UA-Compatible" content="IE=9" />
<%
#else
%>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<%
#endif
%>
</asp:PlaceHolder>
</head>
I am writing a small Sinatra-based app and would like each view to be able to insert various items into the layout, for example the page title or extra CSS/javascript references in the head.
Currently my layout (erb) looks like this (simplified):
<html>
<head>
<title>Hard Coded Title Here</title>
<link rel="stylesheet" ... />
</head>
<body>
<h1>Hard Coded Title Here</h1>
<div id="content">
<%= yield %>
</div>
</body>
</html>
Rather than having the title and CSS/JS references hard coded, I'd like to achieve something along these lines:
<html>
<head>
<title><%= yield :title %></title>
<link rel="stylesheet" ... />
<%= yield :more_head_refs %>
</head>
<body>
<h1><%= yield :title %></h1>
<div id="content">
<%= yield %>
</div>
</body>
</html>
And be able to define the content for those blocks from within each view.
Is this possible, and if so how would I go about doing it?
I came up against this issue at Railscamp recently and luckily Tim Lucas was able to point me to something he forked and worked on called sinatra-content-for. This will cover what you need.
I've found this to be the most robust solution for Rails-style 'content_for' functionality in Sinatra, especially if you're using ERB templates rather than Haml:
http://github.com/kematzy/sinatra-outputbuffer
You can just use #stylesheet in your ruby file