Consider a custom MediaWiki extension that adds a new tag named simplified_example with some JavaScript (just calling alert with provided argument for simplicity):
<?php
if ( ! defined( 'MEDIAWIKI' ) ) die();
$wgExtensionFunctions[] = 'registerTags';
$wgExtensionCredits['parserhook'][] = array(
'name' => 'myTags',
);
function registerTags() {
global $wgParser;
$wgParser->setHook('simplified_example', function ($input, $argv, $parser, $frame) {
$output = $parser->recursiveTagParse($input, $frame);
$title = $argv["value"];
return "<div onclick=\"alert('$title')\">$output</div>";
});
}
?>
Using that I can put following code in a MediaWiki page source:
<simplified_example value="Testing">...</simplified_example>
This results with ... div being clickable - a message box with provided text is displayed. Now I wanted to place this tag inside a template, like this:
<simplified_example value="{{{1}}}">...</simplified_example>
When I put this template into a MediaWiki page:
{{TestTemplate|Testing...}}
Once again I obtain a clickable ... but displayed message is not evaluated and {{{1}}} is displayed instead of provided Testing....
How can I pass the argument from MediaWiki page source down to my custom tag through a template?
Try to use #tag function instead of html in your template, like this:
{{#tag:simplified_example|value={{{1}}} }}
I want to add a simple code to all new post by default
I tried to used this code in .function.php (wpbeginner)
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = "If you like this post, then please consider retweeting it or sharing it on Facebook.";
return $content;
}
I am using plugin named Shortcodes Ultimate
Code:
[su_spoiler title="Download The File" style="fancy" icon="chevron-circle"]Here[/su_spoiler]
I tried to normal use simple html and CSS code but it show the same error for both cases
https://i.stack.imgur.com/wgAs4.png
Try this -: wrap your code is a single quote as you are already using double quotes.
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
$content = '[su_spoiler title="Download The File" style="fancy" icon="chevron-circle"]Here[/su_spoiler]';
return $content;
}
this is my output I need to convert my HTML page to PDF format in YII framework.
I have tried HTML2PDF where it gives me this error.
[ERROR] It seems that HTML2PDF dependencies are not installed… you must install them with composer install
Then I have installed composer also. But the error is same.
Suggest me solution of this or give any new idea.
this is my view code..
<tr>
<?php echo "<td>".$record->inv_article."</td>" ?>
<?php echo "<td>".$record->inv_no."</td>" ?>
<?php echo "<td >".$record->inv_weight."</td>" ?>
<?php echo "<td >".$record->inv_amt."</td>" ?>
<?php echo "<td >".$record->inv_freight."</td>" ?>
<?php echo "<td >".$record->inv_bilticharges."</td>" ?>
<?php echo "<td >".$record->inv_bilticharges."</td>" ?>
<?php $i++; ?>
</tr>
Here is my controller in my project
public function actionGeneratePDF($id){
$mpdf1 = Yii::app()->ePdf->mpdf();
$myhtml=$this->renderPartial('lorryprint', array(
'model'=>$model,'invid'=>$id), true);
$mpdf1->WriteHTML($myhtml);
$file_name= $id.'.pdf';
ob_end_clean();
$mpdf1->Output($file_name,EYiiPdf::OUTPUT_TO_DOWNLOAD );
}
CHECK OUT HERE
I have the same problem couple of months ago, I wanted to convert the html page into pdf in Yii Framework. It took me 3 days to find out how to use it properly. So there are two ways to generate PDF from html by using PHP classes below:
HTML2PDF
mPDF
I have used both but I will prefer you to use mPDF. it is much better than HTML2PDF. Here is method on How to use mPDF in Yii Framework.
First of all you need
YiiPDF - Small Yii extension, that wraps a few PHP libraries (mPDF and HTML2PDF so far) to convert HTML to PDF.
mPDF - is a PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support.
I have used mPDF Version 5.7 Because you don't need a composer to install it.
So just download Yii PDF and mPDF from above links and extract them and then Rename the folders to yii-pdf and mpdf and place them into your project in protected\extensions.
Then open your protected/config/main.php and add the below code.
'components'=>array(
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'mpdf' => array(
'librarySourcePath' => 'application.extensions.mpdf.*',
'constants' => array(
'_MPDF_TEMP_PATH' => Yii::getPathOfAlias('application.runtime'),
),
'class'=>'mpdf', // the literal class filename to be loaded from the vendors folder
/*'defaultParams' => array( // More info: http://mpdf1.com/manual/index.php?tid=184
'mode' => '', // This parameter specifies the mode of the new document.
'format' => 'A4', // format A4, A5, ...
'default_font_size' => 0, // Sets the default document font size in points (pt)
'default_font' => '', // Sets the default font-family for the new document.
'mgl' => 15, // margin_left. Sets the page margins for the new document.
'mgr' => 15, // margin_right
'mgt' => 16, // margin_top
'mgb' => 16, // margin_bottom
'mgh' => 9, // margin_header
'mgf' => 9, // margin_footer
'orientation' => 'P', // landscape or portrait orientation
)*/
)
),
),
Please note: In above code 'class' => 'ext.yii-pdf.EYiiPdf', means that you have a file called EYiiPdf in protected/extensions/yii-pdf/ and similarly that mPDF extension 'librarySourcePath' => 'application.extensions.mpdf.*', exists in protected/extensions/mpdf
Then you can create a function in your controller.
public function actionGeneratePDF($id){
$model = AsfiUsers::model()->findByPk($id);
$mpdf1 = Yii::app()->ePdf->mpdf();
$myhtml=$this->renderPartial('ProfileView', array(
'personal_info'=>$model), true);
$mpdf1->WriteHTML($myhtml);
$file_name= $id.'.pdf';
ob_end_clean();
$mpdf1->Output($file_name,EYiiPdf::OUTPUT_TO_DOWNLOAD );
}
So in my View in ProfileView I have added a button at the top of it.
<?php echo CHtml::link('PDF Version',array('AsfiUser/GeneratePDF','id'=>$this->id), array('class'=>'btn btn-info btn-sm')); ?>
After click on that button, It will download the PDF of that html page. My Profile View has tables too so Thats why I have used mPDF not Html2PDF. In html2pdf, It doesnot give much options to adjust tables margin etc. But in mpdf it is automatically adjust and will be a perfect PDF.
FOR HTML2PDF
In case if you want to use HTML2PDF, all the steps are same. Just download Old version of html2pdf, New version will have problem like dependencies are not installed. Just like you have them now.
All steps are same, just add this into your protected/config/main.php below the mPDF class in yii-pdf component array.
'HTML2PDF' => array(
'librarySourcePath' => 'application.extensions.html2pdf.*',
'classFile' => 'html2pdf.class.php', // For adding to Yii::$classMap
/*'defaultParams' => array( // More info: http://wiki.spipu.net/doku.php?id=html2pdf:en:v4:accueil
'orientation' => 'P', // landscape or portrait orientation
'format' => 'A4', // format A4, A5, ...
'language' => 'en', // language: fr, en, it ...
'unicode' => true, // TRUE means clustering the input text IS unicode (default = true)
'encoding' => 'UTF-8', // charset encoding; Default is UTF-8
'marges' => array(5, 5, 5, 8), // margins by default, in order (left, top, right, bottom)
)*/
)
and then your controller function will be same just replace the name with mPDF.
public function actionGeneratePDF($id){
$model = AsfiUsers::model()->findByPk($id);
$html2pdf= Yii::app()->ePdf->HTML2PDF();
$myhtml=$this->renderPartial('ProfileView', array(
'personal_info'=>$model), true);
$html2pdf->WriteHTML($myhtml);
$file_name= $id.'.pdf';
ob_end_clean();
$html2pdf->Output($file_name,EYiiPdf::OUTPUT_TO_DOWNLOAD );
}
and create the same button in view for it. I hope it will work for you. I have used the same and working perfectly.
UPDATED:
This code works, just try to check you haven't made any mistake and secondly add this below code at the top of your html view file.
<?php
ob_start(); //started buffering
?>
<?php echo CHtml::link('PDF Version',array('AsfiUser/GeneratePDF','id'=>$this->id), array('class'=>'btn btn-info btn-sm')); ?>
It will add the button on the page which u want to make PDF, when u click on the button, it will download the file while it will take few seconds to a minute depending on page size.
Updated 2
add this line to ur controller
$myhtml=preg_replace("/<\\/?a(\\s+.*?>|>)/", "", $myhtml);
So your controller will be like this
public function actionGeneratePDF($id){
$mpdf1 = Yii::app()->ePdf->mpdf();
$myhtml=$this->renderPartial('lorryprint', array(
'model'=>$model,'invid'=>$id), true);
$myhtml=preg_replace("/<\\/?a(\\s+.*?>|>)/", "", $myhtml);
$mpdf1->WriteHTML($myhtml);
$file_name= $id.'.pdf';
ob_end_clean();
$mpdf1->Output($file_name,EYiiPdf::OUTPUT_TO_DOWNLOAD );
}
OR
If the above controller part doesnot work then fix ur code.
Your this line says $model
$myhtml=$this->renderPartial('lorryprint', array(
'model'=>$model,'invid'=>$id), true);
and in ur view you are using $record instead of $model, Have u done it properly in ur loop. Is ur View file showing results or not?
If it is showing properly,then ur view file lorryprint should be like this. add <td> outside the php tag.
<?php
ob_start(); //started buffering
?>
<?php echo CHtml::link('PDF Version',array('AsfiUser/GeneratePDF','id'=>$this->id), array('class'=>'btn btn-info btn-sm')); ?>
//more code here
<td><?php echo $record->inv_article;?></td>
<td><?php echo $record->inv_no;?></td>
<td><?php echo $record->inv_weight;?></td>
<td><?php echo $record->inv_amt;?></td>
<td><?php echo $record->inv_freight;?></td>
<td><?php echo $record->inv_bilticharges;?></td>
<td><?php echo $record->inv_bilticharges;?></td>
<?php $i++; ?>
I'm using yii2 and installed two extension : mpdf , and yii2-barcode-generator-8-types.
Both of them were installed and configured properly and working well.
But what I can't do is to load barcode into pdf.
Here is my code :
Controller :
public function actionPdf()
{
$pdf = Yii::$app->pdf;
$pdf->content = $this->renderPartial('_pdf');
echo $this->renderPartial('_pdf');exit;
return $pdf->render();
}
View :
<div id="showBarcode"></div>
<?php
use barcode\barcode\BarcodeGenerator as BarcodeGenerator;
$optionsArray = array(
'elementId'=> 'showBarcode',
'value'=> '12345678',
'type'=>'code128',
);
echo BarcodeGenerator::widget($optionsArray);
?>
And it show something like this
but If I try to delete all code inside actionPdf() and just write
return $this->render("_pdf");
it show like this:
Please help!!!
I think your controller should be this
public function actionPdf()
{
$pdf = Yii::$app->pdf;
$pdf->content = $this->renderPartial('_pdf');
return $pdf->render();
}
The row with echo $this->renderPartial('_pdf');exit; don't must be used because it prevents the program to invoke correctly the render of the pdf page. If you use this instruction you displays only the render of "html like code" page like you see in result you posted moreover immediately after this instruction you exit form action without invoking the $pdf->render.
I need to use an image to separate my articles (posts). I found this function below
function funny_cat_filter( $content ) {
$content .= '<img src="(image url)"/>';
return $content;
}
add_filter( 'the_content', 'funny_cat_filter' );
Don't mind the function name. This works just fine but with one little pesky detail. It adds image on pages also and I don't want that. I want this only to be added after each post not on every single page.
How do I do that?
You can check if you are in a post with is_single() or in the home with is_home().
function funny_cat_filter( $content ) {
if (is_single() || is_home())
$content .= '<img src="(image url)"/>';
return $content;
}
add_filter( 'the_content', 'funny_cat_filter' );