Passing down MediaWiki template arguments to custom HTML attributes - mediawiki

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}}} }}

Related

Add default code in wordpress post

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;
}

Yii2 mpdf with barcode-generator

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.

How should I use requestAction in the view with CakePHP 3.x

My code:
// View/Activities/index.ctp
...
<div>
<?php echo $this->requestAction('/Activities/ajax_list/'.$categoryId,['return']);?>
</div>
...
//View/Activitest/ajax_list.ctp
....
<?php echo $this -> Html -> image("/img/add1.jpg"); ?>
...
<?php echo $this->Html->link('add_project', array('controller'=>'projects', 'action'=>'add', $categoryId)); ?>
....
I want to include the view 'ajax_list' into the 'index',and it has been displayed but the url of image and link was wrong.
Then I debug the Cake/Routing/RequestActionTrait.php , "requestAction" function I find "$request = new Request($params);" the $request->base , $request->webroot are null.
Could some one tell me how should I fix it?
The $base/$webroot properties not being set in the new request might be considered a bug, or maybe the docs are just missing a proper example solution, I can't tell for sure, you might want to report this over at GitHub and see what the devs say.
Use view cells instead of requestAction()!
Whenever applicable you're better off using view cells instead of requesting actions, as they avoid all the overhead that comes with dispatching a new request.
See Cookbook > Views > View Cells
No models involved? Use elements!
In case no models are involed, and all you are doing is generating HTML, then you could simply use elements.
See Cookbook > Views > Elements
Fixing requestAction()
A possible workaround would be to use a dispatcher filter that fills the empty $base/$webroot properties with the necessary values, something like
src/Routing/Filter/RequestFilterFix.php
namespace App\Routing\Filter;
use Cake\Event\Event;
use Cake\Routing\DispatcherFilter;
class RequestFixFilter extends DispatcherFilter
{
public function beforeDispatch(Event $event)
{
$request = $event->data['request'];
/* #var $request \Cake\Network\Request */
if ($request->param('requested')) {
$request->base = '/pro';
$request->webroot = '/pro/';
$request->here = $request->base . $request->here;
}
}
}
config/bootstrap.php
// ...
// Load the filter before any other filters.
// Must at least be loaded before the `Routing` filter.
DispatcherFactory::add('RequestFix');
DispatcherFactory::add('Asset');
DispatcherFactory::add('Routing');
DispatcherFactory::add('ControllerFactory');
// ...
See also Cookbook > Routing > Dispatcher Filters > Building a Filter

i want to fetch same template in cntroller

my index controller this and showing good html and header and footer is working correct but when i want to add method the css and html not working .
public function index()
{
$data['clients_list'] = $this->clients_model->get_all_clients();
$this->load->view('template/header');
$this->load->view('clients/index', $data);
$this->load->view('template/footer');
}
this is my add method where i want to add html as header and footer
public function add()
{
$this->load->view('template/header');
$this->load->view('clients/add');
$this->load->view('template/footer');
}
The way you are using $this->load->view() is not supported in the framework. You should only be loading one view. If you wish to include multiple views within a single view you must save them within the data to be rendered in the master view and echo them out within that view. To do this you use the third parameter of the view function explained at the codeigniter api: Very bottom of page
An example of this would be:
Controller:
function index(){
$data['clients_list'] = $this->clients_model->get_all_clients();
$data['header'] = $this->load->view('template/header', $data, TRUE);
$data['footer'] = $this->load->view('template/footer', $data, TRUE);
$this->load->view('clients/index', $data);
}
View:
<?php echo $header; ?>
<!-- YOUR INDEX PAGE CONTENT-->
<?php echo $footer; ?>
The third parameter of view() tells the framework to pre-render the view and output the contents as a string value which allows you to save as a variable and echo into the primary page.
Phil Sturgeon wrote a wonderful template library that I have been using in my projects that allows for a webforms style "master page" that you can have the rest of your views rendered inside of so that you do not have to build your header/footer view each time and inject it into every view.
Phil Sturgeon Template Library

WordPress Shortcode adding attributes

I'm writing a shortcode function for WP. Inside the function I have the $content (in this case an image). I need to be able to add a couple attributes to that content and return it in a string, like so:
function Shortcode( $atts, $content=null ){
if(!is_null($content){
return '<div class="wrapper">'. $content .'</div>'
}
}
Currently, just the image is getting spit back, but I need to somehow modify it and add a couple attributes before adding it to the string above.
I need to do something like this:
function Shortcode( $atts, $content=null ){
if(!is_null($content){
// CONVERT $CONTENT TO STRING
$content_html=somefunction($content)
echo $content_html; // <img src='....' />
return '<div class="wrapper">'. $content_html .'</div>'
}
}