resolving paths in aspx user control - ascx

I am building an asp.net website and wish to create a user control that includes a reference to a graphic file in a different directory. Specifically my directory structure looks like:
c:\mywebsite\
c:\mywebsite\images\
c:\mywebsite\usercontrols
The user control will be used in c:\mywebsite\default.aspx
The image is c:\mywebsite\images\logo.jpg
The user control is c:\mywebsite\usercontrols\mycontrol.ascx
If in my ascx file I have:
<img src="../images/logo.jpg" />
Then this renders just fine in the Visual Studio 2010 design view, but not at run time since at run time the control is included in \default.aspx and the path relative to \default.aspx is different from the relative path from \usercontrols\mycontrol.ascx.
How should I reference the graphic from the ascx file so that it will render properly both in design preview as well as at runtime? Also I would like it to render properly in design preview for default.aspx where it is used.

You can use <asp:Image>... control and use the image path as relative path from the web root
<asp:Image ImageUrl='~/Images/logo.jpg" runat="server" />

view html output generated in browser, find there the image file path placed by your usercontrol and make change in path in your usercontrol

Related

How do I add an image to the default layout in Typo3?

I want to add the company logo to the default layout page in Typo3 (located in myextension/Resources/Private/Layouts/Page/Default.html).
However, using the relative path as a source in an img-tag does not seem to work (I used ../../../Public/Images/imagename.jpg). The console shows that Typo3 seems to be looking in the following location: http://localhost/Public/Images/addressicon.jpg.
How do I insert the image located at myextension/Resources/Public/Images/imagename.jpg?
How about /typo3conf/ext/myextension/Resources/Public/Images/imagename.jpg
I think EXT:myextension/Resources/Public/Images/imagename.jpg should work too.

How to embed an image on Github

I use gh-pages to host a website, and I am familiar with markdown. My question, though, makes reference to inserting an image (perhaps saved within Issues) so that it is visible on a regular repository code file. Something like this:
If that file is .md or .rst(not sure if it works for other), you can do that either by saving image to your repo, or to the issues and then if image is in repo you can access it either with absolute or relative path:
![](raw path to your image - click on raw and copy&paste)
![](folder/image.png) folder is in root
If you mind sizing, use html, though I'm not sure if it works with relative paths too.
<img src="<url>" width=500></img>
It's not possible to embed an image so it'd be visible in your raw code as I see on your image. To accomplish it only in a similar way, put your code in backticks and leave the rest in markdown or html.

CQ5.6.1 Text component in the footer to pass same content across all pages

I have a footer.jsp which is expected to appear same across all pages. I added a Text component in the footer.jsp. When the author adds content to this Text component in Home page, I want the content to reflect in the footer of all child pages. Here is how I use the text component in the footer.jsp, but this is not working as I want.
<div class="gelUpdateContent">
<cq:include path="text" resourceType="foundation/components/text" />
Get Live Great <span class="txtRed">updates </span>
</div>
I already tried iparsys component instead of text, which is useful, but then my requirement is to restrict it to text only.
Any help is highly appreciated. Thanks.
I agree with #rakhi's answer of providing absolute path. But there is another way to do this.
Try using iParsys. iParsys configuration is inherited by all child pages. if you include an iParsys and drag-n-drop your footer component in the root page of your site, then that footer component will start appearing in all your child pages.
Instead of providing relative path to the path property in cq:include i.e. (text), provide an absolute path, something like (/content/<project>/<homepage>/jcr:content/text).
Providing relative path creates the text node under each page, whereas absolute path ensures that all the pages read and write to the node present in the path provided always.
This is one way of achieving what you need.
More info on using cq:include can be found here
Well, We can design with following options:
It is depend on your requirement. If you want to have common footer across the site then Put some global path(i.e /content/rootSitePath/) as a cq:include path.
If you want to have footer information get updated on child pages only then use IParsys component.
I would prefer to use option 1, but make sure we are hard coding path. Bette to have utility to determine path.
Thanks,
Jitendra

AEM Page Image in Page Properties Doesn't Apply a sling:resourceType

Using Adobe Experience Manager 5.6.1 (AEM) (Formerly CQ5) I am trying to create a new tab similar to the Image tab in Page Properties. It would be titled "Logo".
I basically just copied the Image tab to create a logo tab and renamed the paths to reflect the logo purpose. For instance, I set the fileReferenceParamater to ./logo/fileReference and requestSuffix to /logo.img.png.
When I edit the properties, I can drag an image into the tab just as I can with the "Image" tab, however, the image never appears there. I am guessing this is because the default image handler is not picking up the request. The error is:
Cannot serve request to
/content/my-site/home-page/en_us/jcr:content/logo.img.png in
org.apache.sling.servlets.get.DefaultGetServlet
When I looked at the content node there was no sling:resourceType. When I added a resource type of foundation/components/adaptiveimage then it worked. However, I noticed that the "Image" node didn't have a sling:resourceType. I guess the img.png.java servlet in the foundation page is handling that request.
I tried creating a logo.img.png.jsp file in my page component to handle the request, but that didn't seem to work.
How can I get AEM to either add the sling:resourceType or to handle the request?
I was facing the similar problem and I found a simpler way to resolve. All you need to do is to add a hidden xtype under the your logo image as below:
<yourlogo
jcr:primaryType="cq:Widget"
<-- other properties -->
xtype="html5smartimage">
<items jcr:primaryType="cq:WidgetCollection">
<resType
jcr:primaryType="cq:Widget"
ignoreData="{Boolean}true"
name="./logo/sling:resourceType"
value="foundation/components/image"
xtype="hidden"/>
</items>
</yourlogo>
Well, after some time experimenting, this is what I ended up doing to get this to work. If there is an easier way, I would be happy to know it.
First, I copied the /libs/foundation/components/page/img.png.java file and added it to my compiled package with some modifications.
#SlingServlet(
resourceTypes = "sling/servlet/default",
selectors = "imgnode",
extensions = {"png","jpg","jpeg","gif"},
methods = "GET"
)
public class SimpleImageServlet extends AbstractImageServlet {
Where img.png.java had the following line:
Image image = new Image(c.resource, "image");
I changed it to:
Image image = new Image(c.resource);
This relies on SCR annotations to generate the OSGi configuration so that this servlet will handle image requests having the imgnode selector. Instead of looking for a child image node it just expects the current resource to be an image.
Second, I added a component to the body.jsp overlay of the page component, like so.
<cq:include path="logo" resourceType="/apps/my-site/components/logo" />
This maps the logo path to a component for rendering.
Third, within the logo.jsp on the component I set the selector to imgnode rather than img.
Image img = new Image(resourcePage, "logo");
img.setSelector("imgnode");
I believe this step would be similar if the adaptiveimage were overlayed. You just need to render out URLs that include the imgnode selector.
Fourth, I setup the logo image dialog tab in page properties to use the expected requestSuffix and set the other properties to point to the logo sub-node.
Examples:
requestSuffix = "/logo.imgnode.png"
fileReferenceParameter = "./logo/fileReference"
Fifth, I made sure that the image dialog tab for the /apps/my-site/components/logo component pointed to itself.
Examples:
requestSuffix = ".imgnode.png"
fileReferenceParameter = "./fileReference"
Now whether it is in page properties, component editing, or final rendering, the image is handled appropriately.
this is a bit of a nuisance with using the image widget controls--only the image component nicely handles the data, and the servlet that handles ".img" is tied to the image component resourceType.
the easiest thing is to just use the value of the fileReference property instead of referencing the image as part of the page. since you're using assets from DAM, this is a reasonable approach.
this doesn't address the issue with a user uploading an image directly. i wanted to suggest having a hidden field like "./logo/sling:resourceType", but testing that locally resulted in an error when trying to save the dialog.
another approach is the following:
<sling:include resourceType="foundation/components/adaptiveimage" resource="${resource.path}/logo" />
(assuming resource is jcr:content). this is effectively the same as adding a sling:resourceType, but there are at least 2 downsides:
the image becomes authorable at that point as opposed to in the dialog
this method only works for rendering a normal tag. it won't work for any sort of background image

Test if a file is loaded

Is there a way in phpUnit to test if for example a certain css file is loaded?
In other words, i want to check if a css file is loaded (if possible). I want to make sure the HMTL output has a style tag with a certain css file.
You can do it as
Foe example the page source will display the css file as
<style src="mycss.css" type="text/css"></style>
Then following statement will check that the element present or not
$this->assertTrue($this->isElementPresent("//style[#src='mycss.css']"));