I am trying to render a single image I have uploaded to my Craft 2 CMS project. However, I have a broken file path so it appears it is trying to render the image but can't find it. I am working locally using http://localhost/ I have created a new assets source as shown in the supporting image.
Next I have added in the following to my _layout.html that lives within my templates folder.
{% for asset in entry.introImage %}
<img src="{{ asset.url }}">
{% endfor %}
The "File System Path" needs to be an absolute path. So use something like /Users/al-76/sites/craft-site/public/img instead of just /img.
Also, fwiw, we've got a great SE site specifically for Craft CMS - https://craftcms.stackexchange.com/
Related
I'm generating a Mustache template within a controller of my rails application. I am able to generate the html just fine. My problem is that I am not able to load in images from the assets folder.
I've tried using ActionController::Base.helpers.image_tag and ActionController::Base.helpers.asset_path and then passing that in as a variable into an image tag in the Mustache template as <img src="{{ asset_path }}" /> for the asset path and the output of the image_tag as it is <div> {{ image_tag }} </div>
I know that image_tag and asset_path are picking up the image because when I put in an incorrect path it outputs an error.
Anybody have any ideas on how to link this image to the Mustache template?
This issue has been resolved. The error was not related to Mustache but to the next phase of the application which is to generate a PDF from the generated HTML.
For reference, I used Rails.root.join('app','assets','..path to image') for the image path.
I'm trying to reference an image in my assets/images folder from a template and having trouble. I feel like I'm missing something very basic but don't think the asset pipeline should be coming into play here. I'm using the angular templates gem. How can I properly reference this image?
* app
* assets
* images
prof_pic.jpg
* javascripts
* templates
myHtml.html
HTML
# I've tried...
<img src="../images/prof_pic.jpg">
<img src="/images/prof_pic.jpg">
<img src="prof_pic.jpg">
If it's to do with Angular you could try using something like <img ng-src="{{location}}/image-name" /> with $location.path() and then the path to the assets directory.
So I have hosted my laravel app in a subfolder lets now refer the root of my project as subfolder. I have a constant base file which has header and footer of the website, I used link of images as
<img src="/img/img1.png">
so it goes to domain.com/img/img1.png instead of domain.com/subfolder/img/img1.png
and if I do
<img src="img/img1.png">
it works fine for the first page but when I navigate to subfolder/user/1 my images brake again because now they are finding images on subfolder/user/1/img/img1.png. I remember once I ran into such situation and someone helped me to set the path of images by adding one line in the header of the website but now I am not able to find it.
Check your root Folder is correct
To avoid this problem, make use of asset() or url() function:
<img src="{{ url(img/img1.png) }}">
Edit: if you plan to attach "subfolder" in url path, then try to edit .htaccess file:
RewriteEngine on
RewriteRule ^/img/(.*)$ http://%{HTTP_HOST}/subfolder/img/$1 [L,R=301]
The code above searches the image /subfolder/img/img1.png when /img/img1.png is found.
I have a rails 4 app that properly uses config.action_controller.asset_host = "xxxxxxx.cdn.com" to render asset urls to point to a CDN.
The app also has a documentation site that uses jekyllrb. Now I want to be able to reference assets from a CDN also but no luck so far.
I'm not able to find documentation about how to setup CDN host for doc site.
I'm trying stuff like this:
<img type="image/svg+xml" src="{{ '/docs/images/' | append: page.logo_image | asset_url}}">
but no luck, I just get the image url but no cdn stuff. All that I found are Shoppify links (I think also use Liquid)
Any hint is more than welcome!
thanks
Found this:
Jekyll configuration for CloudFront To make it easy to serve my assets
from CloudFront, I set up a custom Liquid filter:
module Jekyll
module AssetFilter
def cdn(input)
"#{#context.registers[:site].config['cdn']}/#{input}"
end
end
end
Liquid::Template.register_filter(Jekyll::AssetFilter)
Save this in _plugins/cdn.rb off the root of your Jekyll site’s directory.
Then I added a CDN entry to my _config.yml file. If I comment this line out, my
assets will be served off of S3 (or localhost if I’m running Jekyll locally).
cdn: http://cdn.maxmasnick.com
Whenever I want an asset to be served by the CDN, I pass it through this Liquid filter. For example, in my layout file I have:
<link rel="stylesheet" href="{{ "assets/css/frameless.css" | cdn }}" />
Source:
http://www.maxmasnick.com/2012/01/21/jekyll_s3_cloudfront/
I'm trying to get Symfony2 to work with jQuery UI. I've gotten the JavaScript portion of it working just fine but I'm having trouble getting the images to work.
One thing I read in the Assetic docs is that the cssrewrite filter can take the image paths in CSS files and update them so the paths point to the right places. This looked like exactly what I needed, so I enabled cssrewrite. Here's how cssrewrite changed my paths:
// original
images/ui-icons_222222_256x240.png
// using cssrewrite
../../../app/Resources/public/css/themes/base/images/ui-icons_222222_256x240.png
The first path is no good. The cssrewrite path at least points to the correct path in the filesystem, but relative to my webroot, the cssrewrite path is WAY off. Obviously my app directory is not public.
How do I get the cssrewrite filter to change my paths to something that will actually work?
Here's my stylesheet inclusion. (And yes, I know that the way I'm individually including all these CSS files is dumb, but I'm not worried about that right now.)
{% stylesheets
'../app/Resources/public/css/*'
'../app/Resources/public/css/themes/base/jquery.ui.accordion.css'
'../app/Resources/public/css/themes/base/jquery.ui.all.css'
'../app/Resources/public/css/themes/base/jquery.ui.autocomplete.css'
'../app/Resources/public/css/themes/base/jquery.ui.base.css'
'../app/Resources/public/css/themes/base/jquery.ui.button.css'
'../app/Resources/public/css/themes/base/jquery.ui.core.css'
'../app/Resources/public/css/themes/base/jquery.ui.datepicker.css'
'../app/Resources/public/css/themes/base/jquery.ui.dialog.css'
'../app/Resources/public/css/themes/base/jquery.ui.progressbar.css'
'../app/Resources/public/css/themes/base/jquery.ui.resizable.css'
'../app/Resources/public/css/themes/base/jquery.ui.selectable.css'
'../app/Resources/public/css/themes/base/jquery.ui.slider.css'
'../app/Resources/public/css/themes/base/jquery.ui.tabs.css'
'../app/Resources/public/css/themes/base/jquery.ui.theme.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
There are some known problems with the CssRewrite filter. For what I know, it does not work properly by using the #BundleName notation and a workaround seems to be linking the CSS files by using the bundles/bundle_name path.
Thus your code should be something like this:
{% stylesheets filter='cssrewrite'
'bundles/<your_bundle_name>/css/*'
'bundles/<your_bundle_name>/css/themes/base/jquery.ui.accordion.css'
'bundles/<your_bundle_name>/css/themes/base/jquery.ui.all.css'
'bundles/<your_bundle_name>/css/themes/base/jquery.ui.autocomplete.css'
'bundles/<your_bundle_name>/css/themes/base/jquery.ui.base.css'
'bundles/<your_bundle_name>/css/themes/base/jquery.ui.button.css'
'bundles/<your_bundle_name>/css/themes/base/jquery.ui.resizable.css'
'bundles/<your_bundle_name>/css/themes/base/jquery.ui.selectable.css'
'bundles/<your_bundle_name>/css/themes/base/jquery.ui.slider.css'
'bundles/<your_bundle_name>/css/themes/base/jquery.ui.tabs.css'
'bundles/<your_bundle_name>/css/themes/base/jquery.ui.theme.css'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
Where <your_bundle_name> is obviously the name of the bundle you are working on.
EDIT: remember to give the php app/console assets:install --symlink web command, in order to symbolically link your assets into the web directory.