Image Reference issue in MVC - html

I am creating a line chart in one view(myChartView) and saving it as _ChartFiles/chart01.jpg.
var filePathName = "_ChartFiles/chart01.jpg";
Which is saving at /views/myChartView/_ChartFiles/chart01.jpg . Now in the very next line making a reference it as
<img src="#filePathName" />
but this is not displaying the image. what would be correct way to refer it?

If you want some static files to be accessed directly by the client, you cannot store them in the ~/Views folder because by default (for security reasons) the server would not serve content from this folder.
See ~/Views/Web.Config:
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
Try to save the files in other directory like ~/Static.

You should save it in another folder than "Views" because in MVC this is a folder conventionned for HTML view and no other content, try to save it in "fonts" or whatever else,
and it would be :
<img src="fonts/yourimage.jpg" />

Try giving the image path as
filePathName = "../views/myChartView/_ChartFiles/chart01.jpg";
or
filePathName = "~/views/myChartView/_ChartFiles/chart01.jpg";

//try this one
filePathName = "myChartView/_ChartFiles/chart01.jpg";
<img src="#filePathName" />

Related

Add a block to product page by custom module without editing magento default template

I am trying to add a block to product page by using my custom module.
I do not want to modify any magento default files for this. I know it's possible by modifying the code in view.phtml template. Below is what I tried so far. I have copied the default magento view.phtml file in all module template folder as below. I included layout file inside config.xml of my module and written code for the block.
view.phtml file I placed under each template of module folder.
app/desifn/frontend/default/default/template/mymodule/view.phtml
config.xml file of module -
<frontend>
<routers>
<modulename>
<use>standard</use>
<args>
<module>Module_name</module>
<frontName>modulefrontname</ntNafrome>
</args>
</modulename>
</routers>
<layout>
<updates>
<modulename module="module_name">
<file>module.xml</file>
</modulename>
</updates>
</layout>
</frontend>
This file is under -
app/desifn/frontend/default/default/layout/modulename.xml
<reference name="product.info">
<block type="module_name/product_view" name="product_list">
<action method="setTemplate" ifconfig="module_name/sp_category/status">
<template>modulename/product/view.phtml</template>
</action>
</block>
</reference>
Node modulename is invalid (wrong closing tag)
<updates>
<modulename module="module_name">
<file>module.xml</file>
</module>
</updates>
and also template paths do not match
/mymodule/view.phtml
and
modulename/product/view.phtml
But back to your initial Question:
view.phtml of default template does not contain getChildHtml without any parameters. So the only way to inject custom stuff is to use a block of type core/text_list, which is "product.info.simple.extra". All you need is to make use of before or after attributes in your xml layout.

graphicImage and streamed content primefaces and jsf

So, I have managed to upload images to my desired location and I gave name to these images same name of object property for example: fruit contains name apple and I have an apple.jpg.
I am able to see image directly when I call <p:graphicImage name="apple.jpg" id="image" width="40" height="20" library="images" />
Imagine that I have a datatable which contains all fruits and when i click on some fruit I want to get picture of that fruit.
if(item.getFruit().getLogo().getName() == item.getFruit().getName()){
//show me image
}
I've searched whole stack and I've got lost.
I will assume that:
You have a folder with images
Each image url is saved as String field into Fruit entity.
So, when you load a Fruit entity from database, you have a image full url.
<ui:repeat var="fruit" value="#{fruitBean.fruitListFromDatabase}">
<h:graphicImage value="#{fruit.imageUrl}" rendered="#{!empty fruit.imageUrl}" />
<h:graphicImage library="images" name="no-image.png" rendered="#{empty fruit.imageUrl}" />
</ui:repeat>
The previous code will render an image per Fruit, in case of no image uploaded (imageUrl is null), then a custom no-image.png is show.
h:graphicImage must use specifying library and name attributes when you have a image inside resources folder of your webapp.
Use h:graphicImage with value attribute, to show a full image URL.
Why we must not store uploaded images inside application resources file? Because on redeploy, the images will be lost.
To serve your custom folder, you can use some aproach that allows you create a virtual served directory, for example, if you are using Glassfish, in the glassfish-web.xml, you need to make a reference to external folder with the images:
<property name="alternatedocroot_1" value="from=/media/* dir=/data" />
Now, the images can be found: "your-domain.com/media/some-image.png"

How to create static block for customer login in magento

I want to create a static block on homepage in right side for user login. Please see the below screen short:-
enter image description here
Try to update a layout XML file app/design/frontend/*DEFAULT*/*DEFAULT*/layout/.
You also may create your own local.xml file and put it in the contents.
<layout version="0.1.0">
<default>
<reference name="right">
<block type="your/type" template="path/to/your/template.phtml" />
</reference>
</default>
</layout>

Magento, how to add static url link in Block

I am stuck at adding a url link in block programmatically, I need to add a URL to customized page which edited under CMS/page and I want to add it in .xml file by adding something like below.
<action method="addLink"
translate="label title"
module="catalog">
<label>My Account</label>
<url helper="customer/getAccountUrl" />
<title>My Account</title>
</action>
Above sample retrieve url from module, but no idea what are the parameters should be used for static CMS/page url. Please help me out.
Let me take an example of top.links block to explain this.
<block type="page/template_links" name="top.links" as="topLinks"/>
The “addLink” function is defined in Mage_Page_Block_Template_Links. The definition of the function is
public function addLink($label, $url='', $title='', $prepare=false, $urlParams=array(),
$position=null, $liParams=null, $aParams=null, $beforeText='', $afterText='')
Also the phtml file where the html code for this is written is ‘page/template/links.phtml’.
<reference name="top.links">
<block type="wishlist/links" name="wishlist_link">
<action method="addWishlistLink"></action>
</block>
</reference>
Answer to your question is pretty simple.
Suppose we need to add a new link to top links, lets say a link for a CMS page called Terms and Conditions. To do this open a layout file, let say customer.xml and add the below code:
<default>
<reference name="top.links">
<action method="addLink" translate="label title">
<label>Terms and Condition</label>
<url>terms</url>
<title>Terms and Condition</title>
<prepare>true</prepare>
<position>2</position>
</action>
</reference>
</default>

#{#if DEBUG} not working

My web.config file contains this
<compilation debug="false" targetFramework="4.0">
<assemblies>
// some assemblies
</assemblies>
</compilation>
And in my _Layout.cshtml file I have
#{#if DEBUG}
// include all css and js files
#{#else}
// include the minified and combined versions of the css and js files
#{#endif}
Problem is that the #{#if DEBUG} branch gets executed. If I change that branch to #{#if !DEBUG} then the else branch gets executed. Why is this?
Thanks.
Sachin
The Web.config debug="" attribute does not affect preprocessor symbols.
You can check for that attribute directly like this:
var compilation = WebConfigurationManager.GetSection("system.web/compilation") as CompilationSection;
return compilation != null && compilation.Debug;
(You should put this in a static property in any class, then check that property in a normal if statement)