What is the best way to do page breaks in dompdf?
I have had a look here at the page-break-before css attribute, but it didn't work when I did:
table {page-break-before:auto;}
The page still breaks in the middle of my table.
Is it possible to setup my html/css so that the page will break before the element if the element is going to exceed the page height?
Ideally I would like to divide my html up in to div sections so that each section will start on a new page if it is going to exceed the height of the current page.
Using page-break-inside: auto; basically says to dompdf "do what you would normally do when breaking pages."
To force a page break before / after your table you would use page-break-before: always; / page-break-after: always;.
To ask dompdf to avoid breaking inside an element you would use page-break-inside: avoid;.
You might make quick tests with this online debugger - i finally found my pagebreak and margin issue after days of testing.
Excursus: Did anyone install a debug environment on the development/production environment and can point me to any documentation or tutorial?
Here's a trick: place the <table> you do NOT want to print across multiple pages in another <table>.
In my case it was happened since I have used a table inside another table.
Like,
<table>
<tr>
<td>
<table></table>
</td>
</tr>
</table>
So I did was getting the table out. Solved my issue.
//Firstly assign a variable before starting for loop and set post-increment operator inside for loop. secondly, use with condition of data display item in a single page.
<?php $n=1 ?>
#foreach ($purchases as $key=> $purchase)
<tr >
<td> {{ $key + 1 }} </td>
<td> {{ $purchase->supplier->company_name ?
$purchase->supplier->company_name : "" }} </td>
<td> {{ "S-".$purchase->id }} </td>
<td> {{ salte_items($purchase->purchaseItems) }} </td>
<td> {{ $purchase->created_at->format('d-m-Y') }} </td>
<td> {{ intval($purchase->total) }} </td>
</tr>
#if ( $n % 25 == 0 )
<div style="page-break-before:always;"> </div>
#endif
<?php $n++ ?>
#endforeach
Related
I am using the materialdesign libary' tooltip:
https://getmdl.io/components/#tooltips-section
I'd like to use this feature in a loop, but this won't work of course, because mdl is working with "id's"(tt4 in this example) to trigger the icon and show its tooltip.
How can I get this to work in a loop and link the right tooltip to the right icon?
Thank you so much!
my php laravel blade code:
<td>
#if ($note->text)
<div id="tt4" class="icon material-icons">info</div>
<div class="mdl-tooltip" for="tt4">
{!! md($note->text) !!}
</div>
#endif
</td>
Have you tried dynamically injecting the code using PHP echo.
PHP is the first thing to run so it will evaluate all the other things for you.
echo "<div id="+$blah+">";
something like that
when you generate MDL dynamically, you might need to use this:
componentHandler.upgradeElements($('.mdl-tooltip').get());
I try to execute select * from articles where category_id=1 in laravel eloquent model as below.
$articles = Article::where('category_id', '=', $id)->get();
And i pass this to my view file by using compact method as below.
return view('homeview.index', compact('articles'));
And i use this $articles variable in foreach loop and print each article's title in view file. But the thing is when i try to execute this, my view file is refreshing continuously and incrementing the same div class which i used to print the article titles. I tried to use above code as raw query also. It also generates the same issue.
below is my view file.
<tbody>
#foreach($articles as $article)
<tr>
<td><img src="{{asset('/img_thumbs/'.$article->img_thumb)}}"></td>
<td class="-align-center">
<h4>{{$article->title}}</h4>
<p>{{$article->sub_paragraph}}</p>
</td>
<tr>
#endforeach
</tbody>
Please help me to solve this.
The bottom line is, THere's an error in your HTML.
You are opening <tr> but not closing it.
<tbody>
#foreach($articles as $article)
<tr>
<td><img src="{{asset('/img_thumbs/'.$article->img_thumb)}}"></td>
<td class="-align-center">
<h4>{{$article->title}}</h4>
<p>{{$article->sub_paragraph}}</p>
</td>
</tr> <!-- HERE -->
#endforeach
</tbody>
i used some java scripts for my application. That repeating thing happening because one script file. After i comment it, my page is working fine. I used some template called inspinia and it is happening because inspinia.js file.
So I use this PHP array to store information I need to build a simple HTML structure that looks like so:
{% for key, realisation in realisations %}
<div class="{{ realisation.thumbnail.category }} col-md-4 item">
<div class="grid">
<figure class="effect-oscar">
<img src="images/realisations/{{ realisation.thumbnail.image }}" alt="" />
<figcaption>
<p>
<span>
{{ realisation.thumbnail.name }} • {{ realisation.thumbnail.type }}
</span>
</p>
</figcaption>
</figure>
</div>
</div>
{% endfor %}
{{ realisations }} is a variable I pass to the Twig view:
return $this->render('views/partials/realisations.html.twig', [
'realisations' => $realisations,
]);
Everything is going well and the div get into position nicely as per the screenshot:
However, I want to invert the position of the div so I get the one in the last position into the first position (STEVE DAVID • SITE would be first and ZELDA-BOSS • SITE would be last).
So I naturally go by:
return $this->render('views/partials/realisations.html.twig', [
'realisations' => array_reverse($realisations), // use array_reverse()
]);
But once done, the layout is broken by one div that is shifted of one block and make the others one shifted as well, then leaving a blank space in the middle of the layout:
Does one would have even the slightest idea of what is going on and would be willing to help me?
If you look a little closer, you will notice that STEVE DAVID's box is 1px taller than the other boxes. This 1px is breaking your float grid. Try clearing the float on every 4th element with CSS.
It would be something like:
.item:nth-child(4n+4) {}
Is is possibile to extract a piece of a twig template?
I need to manage a table ajax refresh, I have a twig template for example:
<html>
<body>
<table>
<thead>
<tr><th></th></tr>
</thead>
<tbody id="mypiece">
<tr><th></th></tr>
<tr><th></th></tr>
</tbody>
</table>
</body>
</html>
In the first load I need the whole template, via ajax I need just the #mypiece content, is it possibile to extract it from twig using the DOM id or with some other markers?
The only solution I found is to divide this in two different template and use an include steatment.
whole.html
<html>
<body>
<table>
<thead>
<tr><th></th></tr>
</thead>
<tbody id="mypiece">
{% include 'content.html' %}
</tbody>
</table>
</body>
</html>
content.html
<tr><th></th></tr>
<tr><th></th></tr>
But I think this is really a bad solution...
Well, I personally prefer do actually divide them, but if you intend to get something with AJAX as well - try using embeded controllers (in this case, specifically for your XHR request), for example:
<tbody id="mypiece">
{{ render(controller(
'SomeBundle:SomeController:someAction',
{ 'someParameter': "something" }
)) }}
</tbody>
This is a lot better then to parse some rendered template to get part of it, because to me it seems like design flow.
Even better solution is to return specified json data on ajax call and render it in one of the javascript template engines on the client side.
Hope this helps, cheers.
I need some help. I am working on a backend of a website and I want to create functions where I can re-use the same code instead of duplicating it.
So I will have certain "sections" that contain information, such as:
getQuickInfo
function getQuickInfo() {
echo '
<div class="portlet">
<div class="portlet-header">
<h4>Quick Info</h4>
</div>
<div class="portlet-content">
<table cellspacing="0" class="info_table">
<tbody>
<tr>
<td class="value">'.getCount("total_users").'</td>
<td class="full">Total Users</td>
</tr>
<tr>
<td class="value">'.getCount("count_open_requests").'</td>
<td class="full">Open Support Requests</td>
</tr>
</tbody>
</table>
</div>
</div>
';
}
Now I know I am approaching this the wrong way, that's why I am posting this question. But that is just an example of a Quck Info section I would like to re-use on other pages, so I can sitck it wherever I want and just do getQuickInfo()
For this example, that function works fine. I would like suggestions on a better way to do it, and also for some other sections it won't be that easy it will have some Mysql queries and grabbing information from a database, which I can't store that within an echo.
How does everyone else accomplish stuff like this?
My main goal is to be able to output sections wherever I would like:
getQuickInfo()
getAdminNotes()
getSupportRequests()
etc.
Thanks!
Much as I am loathed to mix raw HTML with PHP code in templates, I know others disagree with me and this is one place where it might be a valid use.
So you would create a file that looks like this:
quickinfo.php
<div class="portlet">
<div class="portlet-header">
<h4>Quick Info</h4>
</div>
<div class="portlet-content">
<table cellspacing="0" class="info_table">
<tbody>
<tr>
<td class="value"><?php echo getCount("total_users"); ?></td>
<td class="full">Total Users</td>
</tr>
<tr>
<td class="value"><?php echo getCount("count_open_requests"); ?></td>
<td class="full">Open Support Requests</td>
</tr>
</tbody>
</table>
</div>
</div>
...and in you main page, you can just do:
include('quickinfo.php');
You can easily adapt this to use the result of queries. You would simply perform the query in the main page, and assign the results to a named variable. Then in the template page you use the data in the named variable to generate the page. This means that you can use the same code to generate different results based on different queries - as long as the result are held in the same named variable.
If you're using php 5 you should considered using PHP's object orientation support.
http://php.net/manual/en/language.oop5.php
This way you can create a class which has methods that print out stuff and hold values and then instantiate this class and call it's methods as needed.
I'm no php guru, but maybe you should create separate .php files for each of those sections (something like quickinfo.php, adminnotes.php, etc) put your html layout inside, and maybe even the php functions you need (or you could put them in a separate file, this depends on whether the logic you need is too complex, if it's fairly simple you can put everything in the same file)
Then you would do something like include('quickinfo.php') wherever you want to use those sections.