Yii2 use of html helper class? - yii2

In forum i see this is not yii2 standard <?= $var ?> .
Yii2 standard code is <?= Html::encode($var) ?>.
Anyone know use of Yii2 html helper class?

The content of <?= $var ?> , tipically is not encoded automatically by yii2 so the values of the $var will be HTML-encoded using
Html::encode($var).
For a useful guide about HtmlHelpers you can see this doc
http://www.yiiframework.com/doc-2.0/guide-helper-html.html
and this ref ..
http://www.yiiframework.com/doc-2.0/yii-helpers-html.html
http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html
Yii2 provide a useful set of Html helpers for a easy code manipulation
l

Related

How To create own Entity Code character in HTML

Is it possible to create custom Entity Code character in HTML ? as if i want to display space on web page so i have to Write but i want to create custom Entity Code like
first i set code admin = 'This is admin'
&admin; so it should display on page as 'This is admin'.
if it is possible so please help me for that.
Hi Dear,
I do not know if it is possible or not in HTML.
but you can create in XML.
Example :
First You have to write top of XML file.
<!DOCTYPE custome_code [
<!ENTITY admin "This is admin">
]>
Now you can use &admin; in any where in XML file.
It's not possible, unfortunately, in current browsers (see Using custom entities in HTML documents) - the list of HTML entities is usually fixed. Using a server-side templating language (PHP, ASP.NET, etc.) would allow you to do something similar with variables. E.g. with PHP:
<?php
$admin = 'This is admin';
?>
Lorem ipsum <?=$admin?> fillare emptimum spatium.
Or in javascript / jQuery you could set up placeholders like <span class="admin"></span> and then fill them using:
$('.admin').html('This is admin');

How to write in HTML DOM?

In sample HTML DOM, how can I write code to add included statements for code? I tried:
<?php $htmlh.='
<?php include('../language/common.php'); ?>'
?>
But I’m getting errors. What did I miss?
How can I write correct code under HTML DOM?

Remove P tags with multiedit plugin

I'm using the multiEdit plugin to create some content regions on a template.
One of those region is for some photos that are going to be using jQuery cycle to rotate through the images.
But, as usual, Wordpress (or the editor rather) is wrapping all of the images in a <p> tag.
I've used the functions hack from CSS-Tricks to remove the <p> tags from the content:
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
But, from what I can tell, it only looks for the_content and not for anything else.
Multiedit uses this: <?php multieditDisplay('name_of_region'); ?> to display the content block in the template.
So, I tried to change the function to this:
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('multieditDisplay', 'filter_ptags_on_images');
But no such luck.
So, I'm not so sure if I'm missing something or just going about it the wrong way.
Ok, well I found a workaround.
I did a write up about it here:
http://ultraloveninja.roon.io/filtering-paragraph-tags-with-the-wordpress-multiedit-plugin
Instead of placing multiEdit fields in your template like this example
<?php multieditDisplay('Top'); ?>
You could prevent the auto print by passing true as the second parameter like this
<?php echo multieditDisplay('Top', true); ?>
So if you want to strip ALL tags from the output, then try this
<?php echo strip_tags(multieditDisplay('Top', true)); ?>
If you want to include certain tags then provide a list of tags to include and pass it as a parameter to strip_tags like this
<?php echo strip_tags(multieditDisplay('Top', true), '<p><a>'); ?>

I want to render html I read from the DB and display the result, instead of the actual html

I'm using a ckeditor in my intranet.
I use it to save formated text, like links, for example.
The thing is, what I have in the ckeditor source is
<p>
this is the new test we need to run.</p>
and what I see in the editor is
test(as a link)
What gets saved in the DB is
<p>
this is the new <a href="http://www.google.com">test</a> we need to run.</p>
which is correct.
But when I want to edit it on ckeditor, what I see is
<p> test</p>
and what I see as source is
<p>
<a href="http://www.google.com">test</a></p>
I would like to see exactly the same when I edit it.
Anoter thing is, I'm using Html.Raw to display it in my index, but it shows me the html. I would like to see the rendered html.
So, if I save
<p>
this is the new test we need to run.</p>
I want to see
this is the new test(as link) we need to run
and not
<p>
this is the new test we need to run.</p>
Any ideas??
Rui Martins
Your problems are the not understanding of htmlentities.
Encoding HTML
http://php.net/manual/en/function.htmlentities.php
Decoding HTML
http://www.php.net/manual/en/function.html-entity-decode.php
Example usage both
<?php
$orig = "I'll \"walk\" the <b>dog</b> now";
$a = htmlentities($orig);
$b = html_entity_decode($a);
echo $a; // I'll "walk" the <b>dog</b> now
echo $b; // I'll "walk" the <b>dog</b> now
?>
Edit (Added asp.net equivalent)
Server.HtmlEncode("<your string>");
Server.HtmlDecode("<your string>");
Try this code:
<%: Html.Raw(HttpUtility.HtmlDecode(YourHTMLStringHere)) %>
It will just render the HTML code

Is it wrong to define ID in body tag for CakePHP?

I am working on a project in which I define ID inside of a <body> tag. For different pages I define different IDs, & I always follow this structure for my all projects. But in our new project which is in CakePHP, my developer said to me that I should never use ID inside the body tag for a CakePHP project.
When I asked him why, he said because we can generate ID through CakePHP.
I don’t know so much about CakePHP, but I think we can define ID inside the body tag for CakePHP & other languages also.
Please provide some links or articles & your suggestions about it.
Thanks in advance :)
You can define id's in your HTML mark-up that's not a problem. But from your question it looks like you are defining id's as an attribute to body tag?
Well you can define id's in body tag. but the problem is in cakePHP you have layouts which usually contain the wrapping HTML of your views, like header, footer etc. So you can not manually define static id's inside body tag for different pages, well you can but then you won't be using layouts.
What your developer telling you I guess is the use of (uuid) unique id's a feature provided by cakePHP to generate unique id's for DOM elements.
you can generate id's via uuid(string $object, mixed $url) function in your views.
To learn more visit : http://book.cakephp.org/view/1091/uuid
You could dynamically add classes to your layout like so:
<?php
$classes = String::insert(':plugin :controller :action', array(
'plugin' => $this->plugin,
'controller' => strtolower($this->name),
'action' => $this->action,
));
?>
<div id="content" class="<?php echo trim($classes); ?>">
<?php echo $content_for_layout; ?>
</div>
This would allow you to namespace your CSS declarations:
.blog.posts.view h2 {
/* ... */
}
Note: IE6 doesn't properly support chaining of multiple classes to select a single element, though there are some Javascript shims if you are still supporting it.