I am trying to add non HTML attribute in htmlOptions array of Yii's CHTML::image($url, $alt, $htmlOptions), but in rendered page these attributes does not get added.
Basically i want to use lazy loading of images which needs to store original image url in 'data-origional' and a placeholder in SRC tag. attribute. For some reasons i can't use a direct HTML <img /> tag in my code.
Thanks for any suggestions guys.
This code works fine:
echo CHtml::image('http://google.com/images/srpr/logo3w.png', '', array(
'data-original' => 'original',
'another-attribute' => 'bla-bla-bla',
));
It returns:
<img
alt="" src="http://google.com/images/srpr/logo3w.png"
another-attribute="bla-bla-bla"
data-original="original"
>
Related
It's first time when i use Codeigniter, so I tried to work with Bootstrap. I knew Bootstrap has a class for images: img-responsive, but you can only use a parameter in img() codeigniter function. So , i tried something like this:
$logo = array(
'src' => 'assets/images/logo.png',
'class' => 'img-responsive',
);
Then i included $logo into img($logo). If I check View Source of page, link looks like:
<img src="http://localhost/assets/images/logo.png" class="img-responsive" alt="" />
but image is not responsive. Any idea ?
This is the original php code:
function lovethemes_pricing_shortcode($atts)
{extract(shortcode_atts(array(
"heading" => '',
"price" => '',
"link" => '',
"name" => '',
), $atts ) );
return '<div class="pricing animated bounceIn">
<section class="head">'.heading.'
<section class="content">
<ul><li class="price">'.$price.'</li>
<li>'.$name.'</li>
</ul></section> </div>';}
add_shortcode('pricing', 'lovethemes_pricing_shortcode');
This is what is written on my page in the backend:
[pricing heading="7 februari 2015"
price="Strak bekleden van een taart"
link="/agenda/workshops/strak-bekleden-van-een-fondant-taart"
name="Info"]
Resulting in this:
http://www.alexandra-van-zandbergen.be/wp-content/uploads/2015/08/Schermafbeelding-2015-08-08-om-13.23.38.png
And what I would like to have is this:
http://www.alexandra-van-zandbergen.be/wp-content/uploads/2015/08/Schermafbeelding-2015-08-08-om-13.22.47.png
I can read and write html and css but no php... Can anyone help me with this please? I've tried to add several codes and nothing is working.
I have to be able to change the image in the backend, I would like to be able to just choose an image from the Wordpress image gallery.
Thanks in advance!
Alexandra
I'm not very familiar with it either, and would need to try it to see if it works, so pls don't shoot me if it does not. However, this function makes use of the shortcode API.
The code tells to create a [pricing] shortcode, currently with 4 attributes. So, if all the rest works, then you most likely can simply add another one.
What I do not understand - and I'm not taking the time to look it up - is why all variables in your code start with $, but not the heading. I'll ignore that since it doesn't seem to be the problem.
Note:
It's best to add:
the image size to the HTML for performance. I'm assuming that you'll
use images of the same size. If you would want to set the image
size, you can create attributes for it too.
an alt text for SEO. Below I use the price attribute.
While I'm at it I would suggest to add a link to the image and title too. People sometimes click on it instead of on the info button. This would make it more user friendly.
So, it then would look like this:
function lovethemes_pricing_shortcode($atts) {
extract(shortcode_atts(array(
"heading" => '',
"price" => '',
"link" => '',
"name" => '',
"img" => '',
), $atts ) );
return '<div class="pricing animated bounceIn">
<section class="head">'.heading.'
<section class="content">
<ul><li class="price">'.$price.'</li>
<li><img src="'.$img.'" alt="'.$price.'" width="247" height="186" /></li>
<li>'.$name.'</li>
</ul></section></div>';
}
add_shortcode('pricing', 'lovethemes_pricing_shortcode');
and your shortcode would be:
[pricing heading="7 februari 2015"
price="Strak bekleden van een taart"
link="/agenda/workshops/strak-bekleden-van-een-fondant-taart"
img="/your/image/url.jpg"
name="Info"]
To make it a little more user friendly, you could also rename the attributes to something that corresponds to the content, f.ex. heading > date
I hope this helps!
With how my template is set up I'm attempting to put a span tag inside of a form label for my Codeigniter login form.
I know I'm doing this wrong but not sure on my fix and hoping someone could clue me in. When I have this rendered it gives me an array to string conversion error.
$attributes = array('class' => 'span12', 'id' => 'username');
echo form_input('<span class="icon16 icomoon-icon-user-3 right gray marginR10"></span>username', '', $attributes);
Keep it simple like:
echo "<label for='short'>**<span class='icon16 icomoon-icon-user-3'></span>**Short Description</label><br/>";
$attributes = array('name'=>'shortdesc','class' => 'span12','id'=>'username');
echo form_input($attributes);
I am reading Beginning CakePHP, and to make it so that you can vote on comments, it tells you to create a couple of AJAX links:
<?=$ajax->link('<li>up</li>',
'/comments/vote/up/'.$comment['Comment']['id'],
array('update' => 'vote_'.$comment['Comment']['id']),
null, false);?>
<?=$ajax->link('<li>down</li>',
'/comments/vote/down/'.$comment['Comment']['id'],
array('update' => 'vote_'.$comment['Comment']['id']),
null, false);?>
This works fine in IE, but in FF it doesn't do anything at all. It doesn't even reach the controller or model, because the links it generates don't do anything.
The HTML it generates looks like this:
<a id="link2128392960" onclick=" event.returnValue = false; return false;" href="/blog/comments/vote/up/1"/>
<li>
<a id="link2128392960" onclick=" event.returnValue = false; return false;" href="/blog/comments/vote/up/1">up</a>
</li>
<script type="text/javascript">
//<![CDATA[
Event.observe('link2128392960', 'click', function(event) { new Ajax.Updater('vote-1','/blog/comments/vote/up/1', {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'vote-1']}) }, false);
//]]>
</script>
Firstly, the HTML output you pasted isn't accurate. It looks like you copied this from Firebug or something instead of your browsers actual 'View Source' page. CakePHP doesn't actually generate self-closing anchor tags in this scenario (<a /> as opposed to <a></a>) like your example shows.
I believe this points out your problem though. The fact that your browser's HTML parser (or Firebug's) tried to correct the code at runtime points to your HTML being malformed. Specifically, you cannot put a block-level element (<li>) inside an inline element (<a>).
<div class="actions">
<ul>
<li>
<?php echo $ajax->link('up', array(
'controller' => 'comments',
'action' => 'vote',
'up',
$comment['Comment']['id']
), array(
'update' => 'vote_' . $comment['Comment']['id']
), null, false); ?>
</li>
<li>
<?php echo $ajax->link('down', array(
'controller' => 'comments',
'action' => 'vote',
'down',
$comment['Comment']['id']
), array(
'update' => 'vote_' . $comment['Comment']['id']
), null, false); ?>
</li>
</ul>
</div>
The above example will produce valid HTML as the inline <a> elements will then be wholly nested within block-level <li> elements. This should hopefully fix the functionality of your page in standards-compliant browsers.
I don't think it's valid HTML to have an anchor tag without an ending anchor tag, like in your first link:
<a id="link2128392960" onclick=" event.returnValue = false; return false;" href="/blog/comments/vote/up/1"/>
Maybe Firefox is mad at you for that.
You also have two tags with the same id, which is also invalid HTML, but might also mean that your Javascript is searching for clicks on the second link but that link is being "eaten" by the first link because you never ended it.
Just throwing out ideas ;p
Using php short tags ("<?") can be considered a bad practice, plus they are being removed in php 6.
I m doing an app in CakePHP, JQuery and Mysql. In my homepage I am listing all my form names. When I click on a form name, it will show the form. Within that view, I have code that looks like this
<?php echo $form->input($r['Attribute']['label'], array(
'type'=>'text',
'style"=width:' => $r['Attribute']['size']
));
?>
to generate a textbox with the label that I got it from $r['Attribute']['label']
and to keep the width of it using that style. However, the width is not working.
This should do it:
<?php
echo $form->input($r['Attribute']['label'], array('type'=>'text','style' => 'width:' . $r['Attribute']['size'] . 'px'));
?>
Two things: Your array key->value pairing was messed up, and you need to give units to the width. I assumed that want you wanted to give it was a width in pixels, but if you just want to set the size of the input field you can do this:
<?php
echo $form->input($r['Attribute']['label'], array('type'=>'text', 'size' => $r['Attribute']['size']));
?>