jQuery QueryBuilder doT.js template syntax inside twig file - twig

I try to rewrite the rule template like this:
$(queryBuilderId).queryBuilder({
templates: {
rule: '\
<div id="{{= it.rule_id }}" class="rule-container"> \
<div class="rule-header"> \
<div class="btn-group pull-right rule-actions"> \
<button type="button" class="btn btn-xs btn-danger" data-delete="rule"> \
<i class="{{= it.icons.remove_rule }}"></i> {{= it.translate("delete_rule") }} \
</button> \
</div> \
</div> \
{{? it.settings.display_errors }} \
<div class="error-container"><i class="{{= it.icons.error }}"></i></div> \
{{?}} \
<div class="rule-filter-container"></div> \
<div class="rule-operator-container"></div> \
<div class="rule-value-container"></div> \
</div>'
}
})
I have included the doT.js in my header, but twig throws me this error:
Unexpected token "operator" of value "=".
Does somebody knows how I can use doT.js template syntax inside my twig file?

Related

Multer only parsing multipart/form-data from postman, not from actual form

I found this question from over a year ago that exactly matches mine, but no answers.
Postman curl:
curl --location --request POST 'http://127.0.0.1:8080/register' \
--header 'Cookie: connect.sid=s%3AZpgwFoDrgb23EX1DPXnehAB4REEoFFRS.s2%2B12XeRx9ugG2E6WtmGbxJmPv9y13unu2EdsUYdS8M' \
--form 'username="bob"' \
--form 'email="bob#bob.com"' \
--form 'password="password"' \
--form 'confirmPassword="password"' \
--form 'image=#"/C:/Users/<me>/Pictures/My Headshot.jpg"'
front-end EJS:
<form action="/register" method="POST" id="register-form" enctype="multipart/form-data">
<div class="input-group mb-3">
<label for="username" class="form-label input-group-text">Username</label>
<input type="text" class="form-control" id="username" placeholder="ILuvBooks101" value="<%= typeof username !== 'undefined' ? username: '' %>">
</div>
<div class="input-group mb-3">
<label for="email" class="form-label input-group-text">Email address</label>
<input type="email" class="form-control" id="email" placeholder="name#example.com" value="<%= typeof emailAddress !== 'undefined' ? emailAddress: '' %>">
</div>
<div class="input-group mb-3">
<label for="password" class="form-label input-group-text">Password</label>
<input type="password" class="form-control" id="password">
</div>
<div class="input-group mb-3">
<label for="confirmPassword" class="form-label input-group-text">Confirm Password</label>
<input type="password" class="form-control" id="confirmPassword">
</div>
<div class="input-group mb-3">
<label for="profilePicture" class="form-label input-group-text">Profile Picture</label>
<input class="form-control" type="file" id="image">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
From Postman, everything works fine, but when testing the actual app's form, I get undefined for req.file and {} for req.body
Any insight would be appreciated!
.......... I forgot to set the name attribute of the fields in the form. Works fine now. It's always the simple things, isn't it?

Htmlspecialchar in twig

I have a problem with Htmlspecialcharon twig I have this
` <div class="row justify-content-center">
<div class="col-lg-10">
{{ form_row(formEdit.description) }}
</div>
</div>`
I checked the twig documentation I found, I tried to fix it by adding (raw)
<div class="row justify-content-center">
<div class="col-lg-10">
{{ form_row(formEdit.description|raw) }}
</div>
</div>
but it doesn't resolve the problem

CheerioJS, looping through <ul> with same class name

I'm trying to loop through each <ul> and get the value of each <li>. The thing is, it only takes the first <ul> and skips the rest.
HTML
<div id="browse-results">
<ul class="tips cf">
<li>tip11</li>
<li>tip12</li>
<li>tip13</li>
</ul>
<ul class="tips cf">
<li>tip21</li>
<li>tip22</li>
<li>tip23</li>
</ul>
<ul class="tips cf">
<li>tip31</li>
<li>tip32</li>
<li>tip33</li>
</ul>
<ul class="tips cf">
<li>tip41</li>
<li>tip42</li>
<li>tip43</li>
</ul>
</div>
Cheerio Parsing
$('#browse-results').find('.tips.cf').each(function(i, elm) {
console.log($(this).text()) // for testing do text()
});
$('#browse-results').children().find('.tips').each(function(i, elm) {
console.log($(this).text())
});
I've tried many more
The output is just the values of the first <ul>.
tip11
tip12
tip13
Please note guys that this is just a snippet example with the same structure of what I'm trying to parse.
I spent nearly 2 hours on this, and I can't find a way to do it.
Try this:
var html = '<div id="browse-results"> \
<ul class="tips cf"> \
<li>tip11</li> \
<li>tip12</li> \
<li>tip13</li> \
</ul> \
<ul class="tips cf"> \
<li>tip21</li> \
<li>tip22</li> \
<li>tip23</li> \
</ul> \
<ul class="tips cf"> \
<li>tip31</li> \
<li>tip32</li> \
<li>tip33</li> \
</ul> \
<ul class="tips cf"> \
<li>tip41</li> \
<li>tip42</li> \
<li>tip43</li> \
</ul> \
</div>';
var $ = cheerio.load(html);
$('#browse-results li').each(function(i, elm) {
console.log($(this).text()) // for testing do text()
});
This will select all li elements which are descendants of #browse-results.

Why generating pagination links raises 'Call to undefined method'?

I've got an problem. This is my first time using pagination.
This is my view:
#extends('base')
#section('title', 'News')
#stop
#section('main')
#if ($news->count())
#foreach($news as $news)
<div class="container">
<div class="doc-content-box">
<legend>{{ $news->title }} <div id="spaceholder"></div>
<p>
<h6><span class="muted"><i class="icon-calendar"></i> {{ $news->created_at }} {{ $news->author }}<span>
</p>
</h6>
</legend>
<div style="margin-top:7px">
<p>{{ $news->content }}</p>
</div>
<div class="btn-group">
<a class="btn btn-primary" href="{{ URL::route('news.edit', $news->id) }}"><i class="icon-pencil"></i> Edit</a>
<a class="btn btn-danger" href="{{ URL::route('news.destroy', $news->id) }}"><i class="icon-trash icon-large"></i> Delete</a>
</div>
</div> <!-- /container -->
<div id="spaceholder"> </div>
#endforeach
{{ $news->links() }}
#else
<div class="container">
<div class="doc-content-box">
<legend>News</legend>
<p>There are no news.<br /><br />If you wish to create a news, you should go to our news management page!</p>
</div>
</div>
#endif
#stop
Then it results into an error Call to undefined method Illuminate\Database\Query\Builder::links().
I've also tried changing #foreach($news as $news) to #foreach($news->results as $news), but then I get an new error:
Undefined property: Illuminate\Pagination\Paginator::$results
The paginator itself works, but the pagination links (next and previous) won't work.
This happens when your query has not been executed. Your variable $news is a query builder not an array of objects. Before calling:
$news->links();
You need to execute your query by calling:
$news = $news->get();
Then after calling the get() method it will return an array representing the result set instead of an instance of Illuminate\Database\Query\Builder.
Note: when you do a foreach in a instance of Illuminate\Database\Query\Builder it will execute the query but the results will be scoped inside the foreach loop. That's the reason that you cannot retrieve the pagination links, because the object you are referencing is the query instead of the results.
If you test that code :
#foreach($news as $new)
<div class="container">
<div class="doc-content-box">
<legend>{{ $new->title }} <div id="spaceholder"></div>
<p>
<h6><span class="muted"><i class="icon-calendar"></i> {{ $new->created_at }} {{ $new->author }}<span>
</p>
</h6>
</legend>
<div style="margin-top:7px">
<p>{{ $new->content }}</p>
</div>
<div class="btn-group">
<a class="btn btn-primary" href="{{ URL::route('news.edit', $new->id) }}"><i class="icon-pencil"></i> Edit</a>
<a class="btn btn-danger" href="{{ URL::route('news.destroy', $new->id) }}"><i class="icon-trash icon-large"></i> Delete</a>
</div>
</div> <!-- /container -->
<div id="spaceholder"> </div>
#endforeach

Why does this curl request not submit the POST data?

I'm trying to use cURL (in a bash script) to load a page on my ISPs site containing my monthly data usage.
Here's the relevent form from the page:
<form method="post" id="Login" name="Login" action="https://signon.bigpond.com/login" class="form">
<input type="hidden" name="goto" value="https://my.bigpond.com/mybigpond/default.do?ref=Net-Header-MyBigPond1"/>
<div class="loginModule roundify">
<div class="loginForm">
<div class="formRow error">
<label for="userName">
Username<span class="reqField">*</span>
</label>
<input type="text" tabindex="1" id="username" name="username" size="30" maxlength="200" onkeypress="EnterKeyPress(event)" value=""/>
</div>
<div class="formRow error">
<label for="password">
Password<span class="reqField">*</span>
</label>
<input type="password" tabindex="2" id="password" name="password" size="30" maxlength="50" onkeypress="EnterKeyPress(event)"/>
</div>
<div class="buttons">
<input class="submit roundify" type="submit" value="Log in" onclick="setCookieForUser();this.disabled=true;document.forms['Login'].submit();" />
</div>
</div>
</div>
</form>
Note that the submit button doesn't have a name.
The function called when text is entered into the form:
function EnterKeyPress(e) {
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
if ( code == 13 && document.getElementById("username").value.length > 0 && document.getElementById("password").value.length > 0 ) {
document.forms['Login'].submit();
e.returnValue = false;
}
}
The cURL command line:
$ curl --user-agent "Mozilla/5.0" --verbose --location --cookie-jar "/tmp/bigpond.cookies" --cookie "/tmp/bigpond.cookies" -o "/tmp/bigpond.html" --data-urlencode "username=MY_USERNAME&password=MY_PASSWORD" https://signon.bigpond.com/login?goto=https://my.bigpond.com/mybigpond/default.do?ref=Net-Header-MyBigPond1
However, the saved html file (/tmp/bigpond.html) is just the logon page still, with text added saying I forgot to enter my username and password. Why is cURL not sending the POST data or what am I doing wrong?
Update: Answered my own question. See below for solution.
Try that :
curl -A "Mozilla/5.0" -b /tmp/c -c /tmp/c -L -s -d "username=<USER NAME>&password=<PASSWORD>" https://signon.bigpond.com/login
And compare the headers of cURL with LiveHttpHeaders firefox module
The problem was passing the POST data to cURL in one argument was causing the data to be mangled when cURL did the URL encoding. The correct usage is to pass each field as a separate argument like so:
curl --data-urlencode "username=XXXXXX" --data-urlencode "password=XXXXXX" ...

Resources