I'm trying to pass a 'mason' variable into a Perl autohandler script that runs before the HTML.
Is this possible.
<!--- MASON -->
<html>
<body>
<%init>
my $sub_headline = 'this is text';
</%init>
###HEADER###
</body>
</html>
<!--- AUTOHANDLER --->
my $m_header = '<div class="m-portlet__head">
<div class="m-portlet__head-caption">
<div class="m-portlet__head-title">
<h3 class="m-portlet__head-text">###TITLE###</h3>
</div>
<p>$sub_headline</p>
</div><!-- /.caption -->
</div><!-- /.head -->';
$html =~ s/###HEADER###/${m_header}/i;
Ended up making a component for the header and adding a condition for the passed in arg. Then pirnt the correct HTML.
Related
I'm having trouble with learning laravel and decided to ask my question here since I can't find an answer via Google etc.
I am trying to return a client from the database via Id, maybe later via name.
This is my form:
<<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Klant invoeren</title>
<link rel="stylesheet" href="{{asset('css/app.css')}}">
</head>
<body>
<p><<form action="{{route('client/'.$client->id.'/show/')}}"
method="get">
<div class="row">
<div class="col-md-4"></div>
<div class="form-group col-md-4">
<label for="price">Achternaam:</label>
<input type="text" class="form-control" name="id">
</div>
</div>
<div class="row">
<div class="col-md-4"></div>
<div class="form-group col-md-4">
{{csrf_field()}}
<button type="submit" class="btn btn-success" style="margin-
left:38px">Zoek klant</button>
</div>
</div>
</form></p>
</body>
</html>
Which redirects to:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Klant invoeren</title>
<link rel="stylesheet" href="{{asset('css/app.css')}}">
</head>
<body>
<div class="container">
<h2>Voer een klant in</h2><br />
<h1>Showing {{ var_dump($client) }}</h1>
</div>
</body>
</html>`
And this is the show method from the Clientcontroller:
public function show($id)
{
$client = Client::find($id);
return view('clients.show', compact('client'));
}
This is the route I'm using:
Route::get('client/{id}/show','ClientController#show');
Can someone spot my mistake, because I can't after messing with this the last few hours.
EDIT: updated code and added the route, now getting the error that the client variable isn't defined in the
You must echo the client id in the form action. So, remove the inverted comma from $client->id. Use the following code :
<form action="{{action('ClientController#show', $client->id)}}"
method="get">
Additionally, remove backtick from the code. Use the following code :
public function show($id)
{
$client = Client::find($id);
return view('clients.show', compact('client'));
}
In your routes/web.php
Route::get('client/{id}/show','ClientController#show');
In your form:
<form action="{{URL::to('client/'.$client->id.'/show/')}}"
method="get">
In your controller:
public function show($id)
{
$client = Client::find($id);
return view('clients.show', compact('client'));
}
In your Client Controller make sure you use the Model that you are referencing to
Assuming App\Client.php Change it to App\User.php if you are referring to user
ClientController
use App\Client;
public function show($id)
{
$client = Client::find($id);
return view('clients.show', compact('client'));
}
Now you can fetch the client model with $client For example $client->id
Make sure you pass the {id} parameter in the route
I would like to exchange node in an XML file using Mojo::DOM.
I'm pretty sure it is possible but I didn't find a way yet.
Given the following XML:
my $xml = q~
<html>
<div>
<p>1</p>
<p>2</p>
<img />
</div>
</html>
~;
I would like to remove the div and instead insert a body tag, so that the result looks like this:
my $xml = q~
<html>
<body>
<p>1</p>
<p>2</p>
<img />
</body>
</html>
~;
I thought about replace, but I didn't find an example where the replacement is the $dom of the replaced tag.
It's very simple to just find the <div> element and use the tag method to change its tag
This program demonstrates. The CSS selector html > div finds the (first) <div> element that is a child of an <html> element
use strict;
use warnings;
use Mojo::DOM;
my $xml = q~
<html>
<div>
<p>1</p>
<p>2</p>
<img />
</div>
</html>
~;
my $dom = Mojo::DOM->new($xml);
$dom->at('html > div')->tag('body');
print $dom, "\n";
output
<html>
<body>
<p>1</p>
<p>2</p>
<img>
</body>
</html>
Below is prototype code, which I am writing for getting content of text files present in a particular folder into div of .hta document.
using document.write I could easily write on document, but I want to write content of text files to specific div.
When I try to run the code, nothing happens.
<html>
<head>
<title>Notes</title>
<script language="vbscript">
Set fso = CreateObject("Scripting.FileSystemObject")
FileName = "C:\Documents and Settings\anamdev\Desktop\demo.txt"
Set fileObj = fso.GetFile(FileName)
Set ts = fileObj.OpenAsTextStream(1, -2)
Set objDiv = Document.getElementById("content")
objDiv = ts.ReadAll
Do While ts.AtEndOfStream <> True
TextLine = ts.ReadLine
Document.getElementById("content").innerHtml TextLine & "<br />"
Loop
ts.Close
</script>
</head>
<body>
<span id="head"></span>
<input type="button" value="Previous" name="pre" />
<input type="button" value="Next" name="nxt" />
<hr>
<div id="content">
</div>
</body>
</html>
The problem is that the code in your <script> is executed as the page is being parsed. This means that at the time the script is run, the "content" element doesn't exist. I would expect that you're actually getting an "Object required" error that isn't being displayed for whatever reason.
There are at least two ways to address this:
Move the script block to the end of the document, just before the close </body> tag:
<html>
<head>
<title>Notes</title>
</head>
<body>
<span id="head"></span>
<input type="button" value="Previous" name="pre" />
<input type="button" value="Next" name="nxt" />
<hr>
<div id="content">
</div>
<script language="vbscript">
Document.getElementById("content").innerHtml = "Hello!"
</script>
</body>
</html>
Wrap the initialization code in a subroutine and call it from the window object's onload event handler:
<html>
<head>
<title>Notes</title>
<script language="vbscript">
Sub Init
Document.getElementById("content").innerHtml = "Hello!"
End Sub
Set window.onload = GetRef("Init")
'Alternatively, you could do this to the <body> element:
' <body onload="Init()">
</script>
</head>
<body>
<span id="head"></span>
<input type="button" value="Previous" name="pre" />
<input type="button" value="Next" name="nxt" />
<hr>
<div id="content">
</div>
</body>
</html>
The Cheran Shunmugavel answer is correct (+1), I'll only append some other issues that I see in the code.
Set objDiv = Document.getElementById("content")
objDiv = ts.ReadAll
Above not make sense. You set an Object to variable objDiv and immediately overwrite this variable with String on the next line.
Anyway, after ReadAll your TextStream is already reach EOF, so next loop do nothing:
Do While ts.AtEndOfStream <> True
TextLine = ts.ReadLine
Document.getElementById("content").innerHtml TextLine & "<br />"
Loop
Also the assignment is wrong.
Object.Property Value 'incorrect
Object.Property = Value 'correct
Briefly, you can go like this:
Set objDiv = Document.getElementById("content")
objDiv.innerHtml = ts.ReadAll
ts.Close
Is there any plugin that transfoms html elements (span, div) into a form ? One example is when editing LinkedIn profile which convert the section to be modified into a form.
Thanks all !
JQuery has the Wrap method, which you can use to throw the whole div / span into a form.
$('.inner').wrap('<form class="newform" action="..." method="..." />');
Found here: http://api.jquery.com/wrap/
Consider the following HTML:
<div class="container">
<div class="inner">Hello</div>
<div class="inner">Goodbye</div>
</div>
Using .wrap(), we can insert an HTML structure around the inner elements like so:
$('.inner').wrap('<div class="new" />');
The new element is created on the fly and added to the DOM. The result is a new wrapped around each matched element:
<div class="container">
<div class="new">
<div class="inner">Hello</div>
</div>
<div class="new">
<div class="inner">Goodbye</div>
</div>
</div>
The second version of this method allows us to instead specify a callback function. This callback function will be called once for every matched element; it should return a DOM element, jQuery object, or HTML snippet in which to wrap the corresponding element. For example:
$('.inner').wrap(function() {
return '<div class="' + $(this).text() + '" />';
});
This will cause each to have a class corresponding to the text it wraps:
<div class="container">
<div class="Hello">
<div class="inner">Hello</div>
</div>
<div class="Goodbye">
<div class="inner">Goodbye</div>
</div>
</div>
Examples:
Example: Wrap a new div around all of the paragraphs.
<!DOCTYPE html>
<html>
<head>
<style>
div { border: 2px solid blue; }
p { background:yellow; margin:4px; }
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<p>Hello</p>
<p>cruel</p>
<p>World</p>
<script>$("p").wrap("<div></div>");</script>
</body>
</html>
I have this HTML code
<div id="first" class="first">
One
<div id="second" class="second">
Second
<div id="third" class="third">
Third
<div id="fourth" class="fourth">
Fourth
<div id="fifth" clas="fifth">
Fifht
<div id="sixth" class="sixth">
Sixth
</div>
</div>
</div>
</div>
</div>
</div>
This code is from an external website.
I want to display 'Hi' using Simple HTML DOM from a URL.
Do you want to see something like this?
$el = $html->find("#first", 0);
while ($child = $el->children(1)) {
$el = $child;
}
echo $el->innertext;