EDIT: If you are using Bootstrap, then it is most likely the reason for this problem. Read here.
I'm trying to generate a PDF of a twig template using KnpSnappyBundle.
The problem is that the generated PDF is displaying the actual link in addition to the link text for all links when it is generated, like in this image:
Is there an option for this within wkhtmltopdf? I've looked at the options using wkhtmltopdf -H and neither disable-external-links nor disable-internal-links resolves this.
Here is the code I'm using to generate the PDF:
$this->get('knp_snappy.pdf')->generateFromHtml(
$this->renderView(
$template,
array(
$key => $array
)
),
$this->container->getParameter("upload_dir") . '/' . $file,
array(
"print-media-type" => true,
"disable-external-links" => true,
"disable-internal-links" => true
)
);
And the HTML:
<strong><u>{{ title }}</u></strong>
And yes, I know the {{ title }} value does not include the actual link because when I use it outside of a link tag, the PDF displays it fine.
I'm trying my best to avoid hacky solutions, but I'm not sure what the problem is.
UPDATE: The problem happens regardless of whether twig variables are used or not.
What I ended up doing was adding another variable to send to the template to let it know when the template was going to be used for a PDF, then run the appropriate JavaScript to remove the links after checking if the variable is defined.
In PDF generation action:
$this->get('knp_snappy.pdf')->generateFromHtml(
$this->renderView(
"my-template.html.twig",
array(
"templateData" => array(
"data" => $session->get("templateData"),
"pdf" => true //<--------- Check this variable in template
)
),
),
$this->container->getParameter("upload_dir") . '/' . $file,
array(
"print-media-type" => true,
"disable-external-links" => true,
"disable-internal-links" => true
)
);
In Twig:
{% if templateData.pdf is defined %}
<script>
$(".work-link").each(function()
{
$(this).prop("href", "#");
});
</script>
{% endif %}
This seems to be working okay for now.
Related
I have a base extension so i can version my website. That means i have not a controller or a repository on the extension. So what i want to do, is to create my own settings on existing elements. I was experimenting around with a text align values on the header content element.
Keep in mind, there is already a setting for this, but i am just
experimenting.
I figured out how to add them and the values are saved on the database.
What i now want to do, is to take the values and add them as a class on FLUID. This is where i stuck. I can not get the values. Any idea how to do it?
After this guide How to enable header_position in TYPO3 7.6
i manage to get my code that far:
On the folder /Configuration/TCA/Overrides/tt_content.php
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
ExtensionManagementUtility::addTCAcolumns('tt_content',[
'header_position_custom' => [
'exclude' => 1,
'label' => 'header position',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['left', 'left'],
['right', 'right'],
['center', 'center']
]
]
]
]);
ExtensionManagementUtility::addFieldsToPalette('tt_content', 'header', '--linebreak--,header_position_custom', 'after:header_layout');
ExtensionManagementUtility::addFieldsToPalette('tt_content', 'headers', '--linebreak--,header_position_custom', 'after:header_layout');
On the folder /Configuration/Typoscript/Constants/Base.typoscript
styles.templates.templateRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Templates/
styles.templates.partialRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Partials/
styles.templates.layoutRootPath = EXT:my_website_base/Resources/Private/Extensions/Fluid_styled_content/Resources/Private/Layouts/
On the /Resources/Private/Extensions/Fluid_styled_content/Resourcs/Private/Partials/Header.html
<h1 class="{positionClass} {header_position_custom} {data.header_position_custom} showed">
<f:link.typolink parameter="{link}">{header}</f:link.typolink>
</h1>
I 've put the class showed just to make sure that i am reading the
file from the path i gave on the constants
File ext_tables.php
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY,'Configuration/TypoScript', 'Website Base');
File ext_tables.sql
CREATE TABLE tt_content (
header_position_custom varchar(255) DEFAULT '' NOT NULL,
);
With all these i get my selectbox where i wanted to be and i get the values on the database. That means that if i select the value "Center" in the selectbox, then it will be saved on the database. How can i get this value and use it as class on the FLUID?
Thanks in advance,
You will find your field in the data object.
For inspecting your fluid variables you can use the f:debug-VH:
<f:debug title="the data">{data}</f:debug>
for inspecting all (in the current context) available variables you can debug _all:
<f:debug title="all data">{_all}</f:debug>
Hint: use the title attribute to identify the output
and don't forget to write a get* and set* function for new fields!
I am sending data via ajax to my PHP callback function inside my custom module... Everything is working great. The problem I am having is: the html i am returning and rendering in the ajax complete funciton is composed of fieldsets which wont expand/collapse. Things i have tested :
1). If I render the same html ( fieldsets ) into one of the custom blocks in that same module, they work great, the collapse and expand.
2). I have tried including this inside the callback function,
drupal_add_js('misc/form.js');
drupal_add_js('misc/collapse.js');
inside the fieldset render array,
return array(
'#type' => 'fieldset',
'#title' => t($title),
'#attributes' => array(
'class' => $class,
),
'#attached' => array(
'js' => array(
'misc/form.js',
'misc/collapse.js',
),
),
);
The
$class
variable contains collapsed and collapsible. I have also tried using
#theme => 'fieldset'
Instead of #type => 'fieldset'
the javascript files
misc/collapse.js
misc/form.js
are already being included from a different function inside my module. And looking at the source of the page, are indeed being included to the head of the page.
This has to be related to bringing them in via ajax, I know when you bring elements into the document via ajax, in-order to set events for those new elements you have to use
$(document).on('event', 'class', function(){
//code here
});
and I am wondering if this could be the reason that the fieldsets wont collapse/expand.
If you get data with AJAX with jQuery once you have to use Drupal.behaviors like this:
Drupal.behaviors.MYBEHAVIOR = {
attach: function (context, settings) {
$('MYELEMENT.MYBEHAVIOR', context).once('MYBEHAVIOR', function () {
// Apply the MYBEHAVIOR effect to the elements only once.
});
}
};
See more at the js documentation https://drupal.org/node/756722
i've been using Yii framework for some time now, and i've been really having a good time especially with these widgets that makes the development easier. I'm using Yii bootsrap for my extensions..but i'm having a little trouble understanding how each widget works.
My question is how do i display the widget say a TbDetailView inside a tab?
i basically want to display contents in tab forms..however some of them are in table forms...some are in lists, detailviews etc.
I have this widget :
$this->widget('bootstrap.widgets.TbDetailView',array(
'data'=>$model,
'attributes'=>$attributes1,
));
that i want to put inside a tab
$this->widget('bootstrap.widgets.TbWizard', array(
'tabs' => $tabs,
'type' => 'tabs', // 'tabs' or 'pills'
'options' => array(
'onTabShow' => 'js:function(tab, navigation, index) {
var $total = navigation.find("li").length;
var $current = index+1;
var $percent = ($current/$total) * 100;
$("#wizard-bar > .bar").css({width:$percent+"%"});
}',
),
and my $tabs array is declared like this :
$tabs = array('studydetails' =>
array(
'id'=>'f1study-create-studydetails',
'label' => 'Study Details',
'content' =>//what do i put here?),
...
...);
when i store the widget inside a variable like a $table = $this->widget('boots....);
and use the $table variable for the 'content' parameter i get an error message like:
Object of class TbDetailView could not be converted to string
I don't quite seem to understand how this works...i need help..Thanks :)
You can use a renderPartial() directly in your content, like this:
'content'=>$this->renderPartial('_tabpage1', [] ,true),
Now yii will try to render a file called '_tabpage1.php' which should be in the same folder as the view rendering the wizard. You must return what renderPartial generates instead of rendering it directly, thus set the 3rd parameter to true.
The third parameter that the widget() function takes is used to capture output into a variable like you are trying to do.
from the docs:
public mixed widget(string $className, array $properties=array ( ), boolean $captureOutput=false)
$this->widget('class', array(options), true)
Right now you are capturing the object itself in the variable trying to echo out an object. Echo only works for things that can be cast to a string.
I want to add 3 custom tags which a MediaWiki admin will add to her templates(for example to the Userlogin.php template for the login page), and these extensions need to be processed by the extension I am building. The tags will be of the form <mytag_forXaction>, <mytag_forYaction>. When the extensions parses through this, they will be replaced with valid HTML tags to display boxes or images or whatever the desired purpose may be.
So far, I have tried doing this:
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is a MediaWiki extension, it is not a valid entry point' );
}
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'Test Parser Function',
'description' => 'A simple example parser function extension',
'version' => 0.1,
'author' => 'Me',
'url' => 'https://www.mediawiki.org/wiki/Manual:Parser_functions',
);
$wgHooks['ParserFirstCallInit'][] = 'buttonParserSetup';
function buttonParserSetup( ) {
global $wgParser;
//apploginbtn will be the tag to be replaced
$wgParser->setHook( 'apploginbtn', 'RenderAppLoginButton' );
return true; // Return true so that MediaWiki continues to load extensions.
}
// Render the output of the parser function.
function RenderAppLoginButton( $input, $argv ) {
$output = "SUCCESSFULLY REPLACED.";
return $output;
}
So now when I add the tag <apploginbtn />, or <apploginbtn></apploginbtn>, or {{apploginbtn}}, or {{#apploginbtn}} to the Userlogin.php file at the desired position, the tag doesn't get replaced.
Any help in achieving the desired outcome will be a lot helpful as am stuck with this since 2-3 days and the documentation isn't helpful at all.
Also, am using MediaWiki 1.9.3 as that's the lowest version I need to start supporting.
Use the UserLoginForm hook. It calls your extension function with the UserLogin template (at SVN) which is used to create the login form. It is an instance of QuickTemplate, and you will be able to edit / stuff it up from your extension code.
Do not try to build a parser extension (tag extension) if you don't target parsed wikitext.
$actions = array(
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
'DELETE' => sprintf('Delete','course_management','do_process','delete',$item['course_id']),
);
In doing so, the edit part is not being displayed.Am i doing anything wrong.
I also tried using the placeholders
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
but still no results. I also noticed that when i remove the class and id attributes in the earlier version, then it works fine.
Can you please give me a satisfactory explanation of this and tell me where am i doing wrong.
EDIT:
Im using this inside Wordpress for creating custom table using WP_List_Table class
function column_course_name($item ) {
//Build row actions
$actions = array(
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
'DELETE' => sprintf('Delete','book_management','do_process','delete',$item['course_id']),
);
//Return the title contents
return sprintf('%1$s%3$s',
/*$1%s*/ strlen($item['course_name'])>0?$item['course_name']:'<span style="color:silver">(No Name)</span>',
/*$2%s*/ $item['course_id'],
/*$3%s*/ $this->row_actions($actions) //row_actions is a method in this class
);
}
update:
Well, its strange to mention but the code works when i use a single class( ie when i delete the space between the two classes for the tag) .
Any thoughts?
Dipesh, maybe you have errors in the code around this snippet.
Try to check your code in isolation. I copied your code to the separate .php script with little set-up and checked $actions array with print_r, like this:
edit_array.php
<?php
$item = array();
$item['course_id'] = 1;
$actions = array(
'EDIT' => sprintf('Edit',
'abf_cm',
'edit_course',
$item['course_id'],
'thickbox edit-box',
'edit_'.$item['course_id']
),
'DELETE' => sprintf('Delete','course_management','do_process','delete',$item['course_id']),
);
print_r($actions);
I ran this script from console and got the following results:
$ php edit_array.php
Array
(
[EDIT] => Edit
[DELETE] => Delete
)
Generated link for $actions['EDIT'] is HTML valid, so one can safely conclude that your code itself is working fine, and error lies somewhere else.