Drupal 7: how to get image url to display image - url

In Drupal 7, I'm using the feeds module to pull in a bunch of books
That's all working perfectly. I am not setting up some views.
the feed pulls in an image url to on o my field like this [http://img.techbook.com/techwords/content/bk/blak/003834/full_image.jpg
but of course I need
<img src="http://img.techbook.com/techwords/content/bk/blak/003834/full_image.jpg" />
to display the image on the page
What is the best method of altering this fields' text, or is there a method so I can automatically format correctly. There are hundres of these, so manually do it is not an option

You can either use Feeds Tamper, which let's you manipulate the incoming feed data before it comes in (ie. wrap the url with img tags): http://drupal.org/project/feeds_tamper
OR
You can simply import the URLs into a field, and then render the URL with a template file that has the img tag wrapped around the field.
Like so: in node--content-type-name-here.tpl.php
<img src="<?php print render($content['field_url']); ?>" />
I would recommend the latter and only use Feeds Tamper for more serious manipulations.

Related

Display desired url of webpage inline with replacement of html code like Google Translate

I want to make app which will switch vocabulary in desired url of webpage Japanese to English.
But firstable I want start form just simply display desired url of webpage inline lust like Google Translate.(See here)
I tried to use open-uri library, and get html from webpage, and display it with code below.
Controller:
def submit
require 'open-uri'
charset = nil
#html = open(params[:url]) do |f|
charset = f.charset
f.read
end
end
View:
<%= #html.html_safe %>
But I have problem with this, which simply won't load Images and some stylesheets in page.
Any way to display image and css?
If you are displaying HTML from another domain on your domain, then any relative URLs used in the HTML (links, scripts, styles, etc.) aren't going to correspond with files that exist on your domain. You are going to have to parse the HTML and either expand the URLs to full URLs that point to the original domain (easier) OR you are going to have to download all the content to your domain using the same path structure.
Example:
To display an image, a site (example.com) could use any of the following src attributes:
<img src="http://example.com/images/logo.jpg" alt="My Logo" />
<img src="/images/logo.jpg" alt="My Logo" />
<img src="../../images/logo.jpg" alt="My Logo" />
If the site always used the full URL like in the first example, you wouldn't have a problem displaying the image. If they used the second one, your site wouldn't be able to find "/images/logo.jpg" on your server. You would have to parse all the img elements and prepend the domain. The third example you would have to do even more work by determining the path to the image based on the current URL you were displaying.

How can I use Cloudinary to output a url with transformation as a string?

I'll preface this by saying that may be approaching this incorrectly. What I'm trying to do is pass the url w/transformation into JS using a data- attribute.
Currently, I'm using the following to generate the image tag:
= cl_image_tag(image.asset.filename.to_s, transformation: "scroller", :"data-medium" => image.asset.filename.to_s)
Which produces this:
<img src="http://res.cloudinary.com/bucket/image/upload/t_scroller/v1373070863/s1ufy3nygii85ytoeent.jpg" data-medium="s1ufy3nygii85ytoeent.jpg">
What I'd like to be able to do is have it output this (Utilizing the t_medium named transition I've set up):
<img src="http://res.cloudinary.com/bucket/image/upload/t_scroller/v1373070863/s1ufy3nygii85ytoeent.jpg" data-medium="http://res.cloudinary.com/bucket/image/upload/t_medium/v1373070863/s1ufy3nygii85ytoeent.jpg">
Currently the cl_image_tag is doing the heavy lifting by generating an image tag with the correctly configured URL. This is great, however I can't seem to find any documentation on how to output a configured URL as a string without the image tag (to use as the data-medium attribute). I could manually configure the URL, but I was wondering if there was a better way?
You can use the cloudinary_url helper to generate the URL without the image tag. For example:
cloudinary_url(image.asset.filename.to_s, transformation: "medium")
As zeantsoi said, if you are using CarrierWave, you can also pass the uploader itself as a parameter:
cloudinary_url(image.asset, transformation: "medium")
On top of Tal Lev-Ami's answer:
If you need to call cloudinary_url outside of a view (for instance in a serializer model for an api), you have 2 options:
rely on "helper": helper.cloudinary_url
or use Cloudinary::Utils.cloudinary_url

multi line tag in grails or html

With a grails app and from a local database, I'm returning some text in a xml format.
I can return it well formed in a <textarea></textarea> tag with the correct indenting (tabulation, line return,...etc.)
I want to go a bit further. In the text I'm returning, there are some <img/> tags and I'd like to replace those tag by the real images themselves.
I searched around and found no solution as of now. I understood that you can't add an image to a textarea (other then in a background), and if I choose a div tag, I won't have the indenting anymore (and therefore, harder to read)
I was wondering if using a <g:textField/> or an other tag from the grails library will do the trick. And if so, How can I append them to a page using jquery.
For example, how to append a <g:textField/> in jquery. It doesn't interpret it and I get this error
SyntaxError: missing ) after argument list [Break On This Error]...+doc).append("<input type="text" id="FTMAP_"+nb_sec+"" ...
And in my javascript file, I have
$("#FTM_"+doc).append("<g:textField id='FTMAP_"+nb_sec+"' ... />
Any possible solutions ?
EDIT
I did forget to mention that my final intentions are to be able to modify the text (tags included) and to have a nice and neat indentation so that it is the easiest possible for the end user.
You are asking a few different questions:
1. Can I use a single HTML tag to include images inside pre-formatted text.
No. You will have to parse the text and translate it into styled text yourself.
2. Is there a tag in the grails standard tags to accomplish this for me?
No.
3. How can I add grails tags from my javascript code.
Grails tags are processed on the server-side, and javascript is processed on the client. This means you cannot directly add grails tags via javascript.
There are a couple methods that can accomplish the same result, however:
You can set a javascript variable to the rendered content of a grails tag. This solution is good for data that is known at the time of the initial request.
var tagOutput = "${g.textField(/* etc */)}";
You can make an ajax request for the content to be added. Then your server-side grails code can render the tags you need. This is better for realtime data, or data that will be updated more than once on a single rendered page.

Display file (PDF/TXT) on form brought from Database in MVC ASP.NET

I want to display file on my form using MVC.
I am bringing a Byte[] array data from the Database, and using FileContentResult I am converting it into a file.I want to now display this file on my page for viewing . How can it be acheived. What code to write in my View for the same.
Assuming you're using Razor, rendering a text file can be done as simple as:
<div>
#(new System.IO.StreamReader("myFile.txt")).ReadToEnd()
</div>
For PDF files, you'll have to find a third-party component to convert to HTML.
You probably don't want to use FileContentResult, that is something generally used for providing the raw file.
In theory though there is nothing different in using any other url
<img src="#Html.ActionLink("View","Image",{id = Model.key})" />
Or you can provide that link in a pdf reference, or as a stylesheet etc.

Rendering html using Struts2

Using Struts2, my goal is to present a simple blog to a user using Struts2 iterators, such as:
Most Recent Topic
response 1
response 2
...
Previous Topic
response 1
response 2
...
Users generate and submit each Topic/Response using a separate form, but, once submitted, I don't want them to edit the blog.
To generate either a Topic or a Response, I provide an editor (like the stackoverflow editor I'm using now) that produces html-formatted text, including whatever styling (bold, underlines, lists, etc.) that the user chooses. The text of the Topic/Response created by the user, including the html tags, is stored in a database.
However, I cannot find a way to render the Topic/Response as html in the blog. For example, text bolded in the editor shows up as <strong>text</strong> in a struts2 s:textarea tag.
I know that the s:property tag has an 'escapeHtml' attribute that will prevent this, but the s:property tag can't layout the text properly, and it seems that only the s:property tag has this attribute.
I've tried using <input value="%{#topic.content}" /> within the iterator instead of s:textarea, but it doesn't seem to recognize the #topic iteration reference.
Is there a way to do this?
use text instated of tax area .Let me know if you still facing this issue.
Use escapeHtml="false". I just tried it myself and it works as intended.
For example, with:
<s:set var="var1"><p>some stuff</p><p>other stuff</p></s:set>
<s:property value="var1" escapeHtml="false" />
renders the paragraph tags as you would expect.
How about using <pre> with <s:property>.
About html <pre> tag:
http://www.w3schools.com/tags/tag_pre.asp

Resources