API Questions on Kentico API.
Version 6.x > API > ResolveUrl not working sometimes using the same template View modes: 
User avatar
Member
Member
petelopez-gmail - 6/8/2012 8:00:38 AM
   
ResolveUrl not working sometimes using the same template
I have a master page with some links and scripts being resolved using ResolveUrl:
<link rel="stylesheet" type="text/css" href="<%#CMS.GlobalHelper.URLHelper.ResolveUrl("~/CMSTemplates/Assets/css/bootstrap.css") %>" />
<script type="text/javascript" src="<%#CMS.GlobalHelper.URLHelper.ResolveUrl("~/CMSScripts/jquery/jquery-.7.1.min.js")%>"></script>


Then I have two sub templates, ProductTemplate and GenericTemplate, that use that master page. However, everywhere I use ResolveUrl is blank when going through the ProductTemplate and works fine in the GenericTemplate.

If I hard code the values it works fine.

User avatar
Kentico Support
Kentico Support
kentico_janh - 6/12/2012 2:24:28 AM
   
RE:ResolveUrl not working sometimes using the same template
Hello,

Could you please post the rendered HTML source code of those two pages (only that part with the link and script)?

Anyway, the URL should be resolved everywhere in the template if it starts with the ~ sign, so please replace your code with the following one:

<link rel="stylesheet" type="text/css" href="~/CMSTemplates/Assets/css/bootstrap.css" />
<script type="text/javascript" src="~/CMSScripts/jquery/jquery-.7.1.min.js"></script>


Best regards,
Jan Hermann

User avatar
Member
Member
Pete - 6/12/2012 7:21:48 AM
   
RE:ResolveUrl not working sometimes using the same template
Hi Jan,

We solved this and it turned out it was a bug caused by us. We used the <%# syntax when we should have been using <%=.

In case anyone runs in to a similar problem in the future the <%# syntax requires an explicit DataBind() call.

Reference on stackoverflow: http://stackoverflow.com/questions/3727877/asp-net-databinding-server-tags-differences-declarative-output-property