从一个主题里果园渲染图像 [英] Render image from a theme inside Orchard
问题描述
我刚刚拿起果园建设我的博客。由于我的努力创造新博客的一部分,我创建一个自定义主题。这个自定义主题功能CSS和图像。
I've just picked up Orchard for building my blog. As part of my endeavour to create this new weblog I'm creating a custom theme. This custom theme features both CSS and images.
我的提问
我的问题基本上可以归结为这样:我如何呈现的形象是主题的一部分?
My question basically comes down to this: How do I render an image that is part of the theme?
我已经试过到目前为止
我曾尝试使用以下命令:
I have tried to use the following:
<img src="@Html.ThemePath("/Content/Header.jpg")" alt="Logo"/>
但是,这并不工作,以极大的。它返回下面的HTML标记:
But that doesn't work to great. It returns the following HTML markup:
<img src="~/Themes/FizzyLogic/Content/Header.jpg" alt="Logo"/>
这不正是它应该返回。我预料到的绝对路径返回到在我的网站上的图像。
Which is not exactly what it should be returning. I expected it to return the absolute path to the image inside my website.
推荐答案
有几个实现这一目标的途径。最好的办法是将网址传递到 Url.Content(...)这样的helper方法:
There are couple of ways of achieving that. The best way would be to pass the URL to Url.Content(...) helper method like this:
<img src="@Url.Content(Html.ThemePath(WorkContext.CurrentTheme, "/Content/Header.jpg"))" />
这会使正确的路径,以您的内容。你也可以舍去开头的波浪号(〜)喜欢的 Html.ThemePath(WorkContext.CurrentTheme,/Content/Header.jpg)。跳过(1)的,它会给你相对路径该应用程序的根,但是这并不是一个很好的解决方案,但。
which will render the proper path to your content. You can also just strip the leading tilde (~) like Html.ThemePath(WorkContext.CurrentTheme, "/Content/Header.jpg").Skip(1), which will give you the path relative to the app root, but that is not a good solution though.
这篇关于从一个主题里果园渲染图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!