I have been able to change each node's Comment Link 'title' text (that on default renders 'Add new comment') with the below code, but if I add HTML, it renders as plain text. I'm trying to add a FontAwesome icon before this text <i class="fa fa-comments" aria-hidden="true"></i>
function MODULE_node_view_alter(&$build) {
$node = $build['#node'];
if (isset($build['links']['comment']['#links']['comment-add'])) {
$build['links']['comment']['#links']['comment-add']['title'] = '<i class="fa fa-comments" aria-hidden="true"></i> Add Comment';
}
}
All I have passed is a $build parameter, but I am unsure of whether or not this is the issue.
Any ideas?
You can render HTML in links by setting the html option to TRUE.
Check theme_links() to see all options.
For example
theme('links', array(
'links' => array(
'title' => '<span>Title</span>',
'href' => 'node/1',
'html' => FALSE, // default
)
))
would result in the span tag being escaped, while
theme('links', array(
'links' => array(
'title' => '<span>Title</span>',
'href' => 'node/1',
'html' => TRUE,
)
))
would render the span tag as html.
So in your case you need to add the following row.
$build['links']['comment']['#links']['comment-add']['html] = TRUE;
If you can't include html in that field, as that is the type of field which may need to remain as plain text and translatable, you can use css to prepend the icon.
a:before {
font-family: FontAwesome;
content: "\f086";
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<a>Add Comment</a>
Related
I have a Wordpress site that needs some fixes and one of my issues is, that I can't add an anchor tag to the Customize page options list. What I mean is the following:
This is my information module that I can change, but for now it accepts only the <strong> tags along with some others that have been added to the array() that it is using. Here is the code that is working for me now, but as you can see, the anchor has been hardcoded into it:
<div class="text">
<a id="mainPhone" href="tel:02086109182">
<?php echo wp_kses( nl2br( $header_phone ), array( 'br' => array(), 'strong' => array(), 'span' => array() ) ); ?>
</a>
</div>
How can I switch from this to something like this:
<div class="text">
<?php echo wp_kses( nl2br( $header_phone ), array( 'br' => array(), 'strong' => array(), 'a' => array(), 'span' => array() ) ); ?>
</div>
I have added 'a' => array() to it, and as it seems it adds an anchor to the content (it gets underlined and etc.) but It is not clickable (my guess is that the href attribute needs to be added in some way?).
How can I do this? Thanks in advance!
I'm using kartik mpdf extension and trying to style the pdf using "cssFile" property.
But any font I want to set (even from Web Safe Fonts or my oun font-face) don't effect the content of pdf file.
Any help?
I thank you should configure cssFile and cssInline in kartik,
For example in PDF controller you have
public function actionPdf()
{
$pdf = new Pdf([
'mode' => Pdf::MODE_CORE,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $contents,
'filename' => 'Filename',
'cssFile' => '#vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.css',
'cssInline' => '.modal-footer{text-align:left;}div.modal-body{padding:0px;}',
'options' => ['title' => 'Devis'],
'methods' => [
'SetFooter'=>[$footer],
]
]);
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'application/pdf');
return $pdf->render();
}
And you should go to this file in vendor folder to do what you want in css #vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.css
And the required style (for exemple color: #fff !important) you should do that in this ligne 'cssInline' => '.modal-footer{text-align:left;}div.modal-body{padding:0px;}',
he asked how change font-family in pdf file.
Names of basic fonts are located in config_font.php.
You can add custom fonts in this file.
Example
$this->fontdata = array( ... "pompadur" => array( 'R' => "Pompadur.ttf", ), ... )
paste to your html: style="font-family: Pompadur"
I've been using "tiny_mce_before_init" in WordPress to add my own custom styles to the style dropdown in the editor.
Everything has been working fine but now I need to add a style that doesn't just add one element but two. Do you know if that's possible?
Here's how I'm adding single elements:
<?php
add_filter('tiny_mce_before_init', 'my_tinymce_styles');
function my_tinymce_styles ($init) {
$styles = array(
array(
'title' => 'Small',
'inline' => 'small',
'wrapper' => false
),
array(
'title' => 'Bar',
'block' => 'div',
'classes' => 'bar',
'wrapper' => true
)
# Etc...
);
# Insert the array, JSON ENCODED, into 'style_formats'
$init['style_formats'] = json_encode($styles);
return $init;
}
And this works as expected. The user selects some text, chooses "Bar" from the "Styles" dropdown and the text is wrapped in <div class="bar">...</div>.
However, now I need to do that same but add <div class="section"><div class="inner">TEXT_HERE</div></div> - how can I do that?
i am newbie in Cakephp trying to create a space between radio box and a label
<span class="label"><b>Gender</b></span>
<?php $options=array('M'=>'Male'."<br>" , 'F'=>'Female');
$attributes=array('legend'=>false,'label'=>'gender_male.','class'=>'radio');
echo $this->Form->radio('gender',$options,$attributes);?>
</div>
i have created a radio box in Cakephp but there is no space between the box and label is coming ... how can i create a space .
Adding margin or padding to one of the elements depending on your design goals.
This is not a CakePHP issue but a CSS styling task. See http://www.w3schools.com/css/
You can simply use the following code:
<style type="text/css">
label{padding-left:5px;}
</style>
<span class="label"><b>Gender</b></span>
<?php $options=array('M'=>'Male'."<br>" , 'F'=>'Female');
$attributes=array('legend'=>false,'label'=>'gender_male.','class'=>'radio', 'div' => false, 'separator' => '');
echo $this->Form->radio('gender',$options, $attributes);?>
You can use labels in styled span with padding but don't forget to use escape False otherwise it will show you the entire span. Please see the <span style="padding:0 15px 0 15px;">No</span> part of the code.
<?php
echo $this->Form->radio('lifestyle_drinking',
[
[ 'value' => '0', 'text' => '<span style="padding:0 15px 0 15px;">No</span>'],
[ 'value' => '1', 'text' => 'Yes'],
[ 'value' => '2', 'text' => 'Ocassionally']
],
[ 'div' => false,
'class' => 'form-control col-xs-10 col-sm-10',
**'escape' => false**
]);
?>
Try it
<span class="label"><b>Gender</b></span>
<?php
$options=array('M'=>' Male'."<br>" , 'F'=>' Female');
$attributes=array('legend'=>false,'label'=>'gender_male.','class'=>'radio');
echo $this->Form->radio('gender',$options,$attributes);?>
</div>
I am new to Drupal 7.
I have different basic pages, I want to loop through every page using the meta tag:
<meta http-equiv="refresh" content="20; url=http://sitename/node/page2" />
page 2 would have the meta tag
<meta http-equiv="refresh" content="10; url=http://sitename/node/page3" />
How can I do this? i want the meta tags to be added on basic pages only
I tried using the TEMPLATEUSED_preprocess_html to add the meta tag however I already realized it was wrong since it's not dynamic and applies to every page.
drupal_add_html_head is useful to add tags to head, Please check the example below.
// First, we must set up an array
$element = array(
'#tag' => 'link', // The #tag is the html tag - <link />
'#attributes' => array( // Set up an array of attributes inside the tag
'href' => 'http://fonts.googleapis.com/css?family=Cardo&subset=latin',
'rel' => 'stylesheet',
'type' => 'text/css',
),
);
drupal_add_html_head($element, 'google_font_cardo');
This will output the following HTML:
<link href="http://fonts.googleapis.com/css?family=Cardo&subset=latin" rel="stylesheet" type="text/css" />
This is an old question, but it remains without a more specific response. It seems that we have to use preprocess_html to add a head element within template.php. $node isn't available (at least I couldn't access it from within template.php/preprocess_html) but I could get the path using drupal_get_path_alias, which is what the original question requested.
This is my working example:
function THEMENAME_preprocess_html(&$variables) {
if (drupal_get_path_alias() == "node/45") {
$meta_refresh = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'refresh',
'content' => '900, url=/node/45',
),
);
drupal_add_html_head($meta_refresh, 'meta_refresh');
}
}
Using a case statement might better serve Warren's two paths.