This is my code :
return redirect()->action('AdminController#index')->with('succes', ['Mission Ajoutée']);
in blade :
#if(Session::has('succes'))
<div class="alert alert-success">
{{ Session::get('succes')}}
</div>
#endif
I would like to print this message for 10secs. Is is possible to do this with a blade template or with HTML? I want to achieve this without using Javascript.
Related
I have a component in the laravel blade and I want set class or inline style to a component without passing any data but my code not working and mt-5 is not set to x.atom.form component.
My simple code is:
<x-atom.form class="mt-5" :data="$fields->main_form"></x-atom.form>
ِYou assume my component code is:
<section class="contact-form"></section>
resources\views\components\atom\form.blade.php
<section {{ $attributes->merge(['class' => 'contact-form']) }}>
{{-- ... --}}
{{-- ... --}}
</section>
some_file.blade.php
<x-atom.form class="mt-5"></x-atom.form>
docs
ref
ref2
I made a form with the FormBuilder of Symfony.
When I put my form in twig, the form_start(form) and form_end(form), it add a tag for each input.
I don't understand why twig adds a tag.
What is the solution to remove this tag
Thanks for your answer :)
Also, my formbuilder is like that :
->add('title', TextType::class, array(
'label'=>false,
'attr'=>array('autofocus'=>true)
))
my twig is like that :
{{ form_start(form) }}
<div class="row">
<div class="col-sm-9 p-1">
{{ form_row(form_record.title, {'attr':{'class':"form-control", 'placeholder':"Description"|trans, 'title':"Description"|trans }}) }}
{{ form_errors(form_record.title) }}
</div>
<div class="col-sm-1 pt-2">
<button type="submit" class="btn btn-success btn-circle btn-sm">
<i class="fas fa-plus"></i>
</button>
</div>
</div>
{{ form_end(form) }}
and the result in the html source code is :
<div class="row">
<div class="col-sm-9 p-1">
<div>
<input type="text" id="app__title" name="app_[title]" required="required" class="form-control" placeholder="Description" title="Description">
</div>
</div>
</div>
So Twig add the
<div>
that I don't want. How can I remove this autocompleted tag?
I tried the
{% do form_record.title.set rendered %}
but maybe I think that it does not work.
Edit: Okay it seems I misunderstood the issue at first.
I thought you wanted to hide a field you had in your form which can be done with
{% do form.myField.setRendered %}
Now that I understand the issue, I believe it comes from the way your field is being printed.
There are 3 main components to a form field.
Label: form_label(form.field)
Widget: form_widget(form.field)
Errors: form_errors(form.field)
There is a way to print all three components at once. The function is
form_row(form.field)
Here comes the culprit: form_row(). Because it normally prints 3 different components, it adds a div around it!
Futhermore, by looking at the form type and seing 'label' => false, I can say that the label was printing at first using form_row.
To avoid having to define 'label'=>false everytime, you can simply print your form field in this manner:
{{ form_widget(form_record.title, {'attr':{'class':"form-control", 'placeholder':"Description"|trans, 'title':"Description"|trans }}) }}
{{ form_errors(form_record.title) }}
You can simply omit {{form_label(form_record.title)}} and it won't print.
On the other hand, I also noticed something that might be okay but seem wrong with the given example.
In the twig you shared, the form starts with {{ form_start(form) }} but then the field is {{ form_row(form_record.title)}}.
From where I come from form_record is undefined here. I would use {{ form_row(form.title)}}
Anyways, the explanation for the difference between form_row and form_widget can be found here: Symfony form differences between row and widget
Enjoy!
Method render does not exist error also in links() method
this is my blade
blade.php
this is my controller
controller.php
render() isn't used for pagination anymore.
In Laravel 5.4 you use links() to display the links:
<div class="container">
#foreach ($news as $newsItem)
{{ $newsItem->whatever }}
#endforeach
</div>
{{ $news->links() }}
Displaying Pagination Results
When calling the paginate method, you will receive an instance of Illuminate\Pagination\LengthAwarePaginator. When calling the simplePaginate method, you will receive an instance of Illuminate\Pagination\Paginator. These objects provide several methods that describe the result set. In addition to these helpers methods, the paginator instances are iterators and may be looped as an array. So, once you have retrieved the results, you may display the results and render the page links using Blade:
<div class="container">
#foreach ($news as $newsItem)
{{ $newsItem->whatever }}
#endforeach
</div>
{{ $news->links() }}
See more about Laravel 5.4 pagination here
I'm looking for a simple way to create some static html page designs but using handlebars partials to ease the handover to the developer. i.e. create
index.html
sidebar.html
main.html
product.html
product_stub.html
and so on. Then a simple way to build up the pages so I can see them in Chrome:
index.html:
<html>
...
<body>
<div class="sidebar">{{ include sidebar.html }}</div>
<div class="main">{{ include main.html }}</div>
</body>
main.html:
{% for i in 0 to 10 %}
{{ include product_stub.html }}
{% endfor %}
Then product_stub.html might look like:
<div class="product-stub">
<h2>Product Name</h2>
<p>some lipsum text...</p>
</div>
Then ideally the developer could take these same files, add in the magic - then the designer could edit to tweak the design..
Take a look at assemble, it's specifically for this purpose.
We created a "load" handlebars helper that loads in a template:
cache = {}
template = (name) ->
t = cache[name]
if t?
return t
raw = null
$.ajax
url: "/static/templates/#{ name}.hbs"
async: no
type: 'GET'
.done (text) ->
raw = text
.fail (err) ->
if window.appdebug
# if app is running in "debug" mode, fallback to possible design
# template
url = "/static/design/#{ name }"
url = url + '.hbs' if not url.match(/\.hbs$/)
$.ajax
url: url
async: no
type: 'GET'
.done (text) ->
raw = text
if not raw?
throw "Cannot fetch template #{ name }"
t = Handlebars.compile(raw)
cache[name] = t
t
Handlebars.registerHelper "load", (name, ctx) ->
new Handlebars.SafeString(template(name)(ctx))
Then in debug mode I can have a template that does this:
<div class="container content">
{{load "common.breadcrumbs"}}
<div class="row">
<div class="span12">
<div class="main">
{{load "product.edit.maindetails"}}
...
So we can then see a whole page split up into handlebars templates by the designers that's easy to add in the rest of the HBS code by the devs.
Beginner in Symfony2, so maybe it's a dumb question.
I would need to get the response of an HTTP query (external server) and put it on a template before sending it to the client.
Like
<div id="main_content">
Lorem Ipsum
<div id="external_content">
{% get_content_by_url 'http://external.com/uri' params_object %}
</div>
</div>
Or maybe I should get the response from the controller and pass it as a variable to the template ?
What is the best practice (or am I on a totaly wrong way :) ?
you can use this bundle
after enters this code in your controller:
$crawler = $client->request('GET', 'http://symfony-reloaded.org/');
$response = $client->getResponse();
$content = $response->getContent();
and finaly in file twig :
<div id="main_content">
Lorem Ipsum
<div id="external_content">
{{ content }}
</div>
</div>