I have the following code inside my asp.net MVC view:-
<img class="thumbnailimag" src="~/Content/uploads/#item.ID.ToString()" + ".png" />
but I am unable to concatenate the .png to my href & src . can anyone advice please ?
Thanks
You'll want to wrap the code in parentheses, as explained here. No need to call .ToString() then:
href="~/Content/uploads/#(item.ID).png"
Your quotes are not closed properly.
href='#string.Format("~/Content/uploads/{0}.png", item.ID)'
Complete Code
<a href='#string.Format("~/Content/uploads/{0}.png", item.ID)'><img class="thumbnailimag" src='#string.Format("~/Content/uploads/{0}.png", item.ID)' /></a>
Alternatively, declare fileName outside of the href (IMO makes it more readable)
#{
var fileName = item.ID.ToString() + ".png";
}
<img class="thumbnailimag" src="~/Content/uploads/#fileName" />
Related
so i want to make all my img links into a simple word/code in html and css
Example:
//Not like this
<img src="https://img1.com">
<img src="https://img2.com">
<img src="https://img3.com">
//I want to do something a little bit more like this instead
value01 = https://img1.com
value02 = https://img2.com
value03 = https://img3.com
<img src="value01">
<img src="value02">
<img src="value03">
I don't know what to do I am new to HTML and CSS
I think you can't do this in html because
The <img> tag is used to embed an image in an HTML page, maybe you can do this in python, instead, you can do this:
<b>
<img src="value1.jpg" alt="Value1" >
</b>
Source :
img tag html
there are two ways I can think of.
::THIS FIRST OPTION ONLY WORKS IF YOU SAVE THE PAGE IN (.PHP) EXTENSION
1° Method => You can create a php file apart, store the links of images in variables like this.
< ? php
$img = 'https : // upload . wikimedia . org /wikipedia/commons/thumb/c/c3/Python-logo-notext . svg/1200px-Python-logo-notext . svg . png';
? >
next, you can call this file in the main page/index.
< ? php
include ". /page/images . php";
? >
< html >
< img src="< ? php echo $img; ? >" alt="" srcset="">
< / html >
2° Method => you can just save the image to a folder easy to target.
create a folder inside the same folder you are accessing your main page.
for example: I created a folder called (img) in the same folder my index.html is found, save the image with a short name.
so to access that image i would call the image like this
< img src="image/img.png" alt="" srcset="">
I need to find an automated way to update href URLs in a HTML file with the corresponding image alt text the anchor tag is wrapping while also including leading and closing RPL text.
Start:
<img src="/images/image.jpg" alt="ALT_TEXT">
End:
<img src="/images/image.jpg" alt="ALT_TEXT">
Breaking down the new URL:
First Variable: ${clickthrough('<br>
Second Variable: ALT_TEXT<br>
Third Variable: ')}
Anyone know where I should start in designing a solution for this problem? What coding language might handle this?
The language that you are looking for is JavaScript.
Here is a working example that does what you mentioned. (and here is a codepen with the same example)
const anchorElements = document.querySelectorAll('a');
[...anchorElements].forEach((anchor) => {
const altText = anchor.querySelector('img').alt;
anchor.href = "${clickthrough('" + altText + "')}";
})
<img src="https://place-hold.it/300x100" alt="text1">
<img src="https://place-hold.it/300x100" alt="text2">
<img src="https://place-hold.it/300x100" alt="text3">
I know how to use the smarty mailto function to create mailto anchor links with encoding. But I am wondering if it is possible for example to insert html image tags [<img>] into the output of this function.
I have tried:
[SMARTY]
{$text = '<img src="/images/qr_code.jpg" alt="member sign up qr code">'}
{mailto address="test#example.com" encode="hex" text={$text}}
[HTML RESULT]
<a href="mailto:%74%65%73%74#%65%78%61%6d%70%6c%65.%63%6f%6d">
<img src="/images/qr_code.jpg"
alt="member sign up qr code" >
</a>
I am after this output rather:
<a href="mailto:%74%65%73%74#%65%78%61%6d%70%6c%65.%63%6f%6d">
<img src="/images/qr_code.jpg"
alt="member sign up qr code">
</a>
It seems, from reading this code https://bitbucket.org/pferor/dbless/src/04b228943e39/dbless/lib/smarty/plugins/function.mailto.php, that when you use the "hex" encoding it not only encodes the address but also the text (line 147):
$text_encode = '';
for ($x=0; $x < strlen($text); $x++) {
$text_encode .= '&#x' . bin2hex($text[$x]).';';
}
Not sure if that's the problem though.
If you don't mind editing the Smarty source youmight be able to change this line (153):
return '<a href="'.$mailto.$address_encode.'" '.$extra.'>'.$text_encode.'</a>';
To this:
return '<a href="'.$mailto.$address_encode.'" '.$extra.'>'.$text.'</a>';
To make it work.
If you try "none" encoding does it show the image then?
insertText is java script that accepts two string paramters
I need to pass two strings
first parameter:
<img src="
second
">
I just cant figure out how to pass double quote as parameter
This works
<a onClick="insertText('<em>', '</em>'); return false;">Italic</a>
This does not
<a onClick="insertText('<img src=/"', '/">'); return false;">Image</a>
Prints '); return false;">Image
You want to use \ rather than /
The escape character for JavaScript is \, not /. So try this:
<a onClick="insertText('<img src=\"', '\">'); return false;">Image</a>
Update:
The solution above doesn't work, because the double-quotes "belong" to the HTML and not to the JavaScript, so we can't escape them in the JavaScript code.
Use this instead:
<a onClick="insertText('<img src=\'', '\'>'); return false;">Image</a> // --> <img src='...'>
or
<a onClick='insertText("<img src=\"", "\">"); return false;'>Image</a> // --> <img src="...">
Since you are using jQuery, why don't you do it the jQuery way?
insertText = function(a, b) {
// your insertText implementation...
};
$('a').click(function() { // use the right selector, $('a') selects all anchor tags
insertText('<img src="', '">');
});
With this solution you can avoid the problems with the quotes.
Here's a working example: http://jsfiddle.net/jcDMN/
The Golden Rule for that is reversing the quotation which means I use the single quotation ' inside the double quotation " and vice versa.
Also, you should use the backslash symbole to espape a special character like ' and ".
For example,
the following commands should work as they apply the rules mentioned above...
<a onClick="insertText('<em>', '</em>'); return false;">Italic</a>
or
<a onClick='insertText("<em>", "</em>"); return false;'>Italic</a>
or
<a onClick="insertText('<img src=\"', '\">'); return false;">Image</a>
or
<a onClick='insertText("<img src=\'", "\'>"); return false;'>Image</a>
I hope this helps you ...
You need to escape it.
<a onClick="insertText('<img src=\"', '\">'); return false;">Image</a>
I'm trying to get the email to a friend link from this page using xpath.
http://www.guardian.co.uk/education/2009/oct/14/30000-miss-university-place
The link itself is wrapped up in tags like this
<li><a class="rollover sendlink" href="http://www.guardian.co.uk/email/354237257" title="Opens an email form" name="&lid={pageToolbox}{Email a friend}&lpos={pageToolbox}{2}"><img src="http://static.guim.co.uk/static/80163/common/images/icon_email-friend.gif" alt="" class="trail-icon" /><span>Send to a friend</span></a></li>
I'm using this for my query, but it's not quite right.
$links = $xpath->query("//a/span[text()='Send to a friend']/#href");
You're trying to get the href of the span there. I think you want
$links = $xpath->query("//a[span/text()='Send to a friend']/#href");
You need to use something like this (since href is an attribute of a):
$links = $xpath->query("//a[span/text()='Send to a friend']/#href");
The href is an attribute of the anchor hence you need:-
$links = $xpath->query("//a[span[text()='Send to a friend']]/#href");
try this
$links = $xpath->query("//a[span='Send to a friend']/#href");