Developer forum

Forum » CMS - Standard features » Get frontpage id or link

Get frontpage id or link

Jonas Mersholm
Reply

Hey Dw-Guys :-)

I's there any neat feature to get the current websites frontpage-page id or a url to the page? 

The scenario is pretty straight forward. We have a multi-site solution with seperate websites(module) pr. language, and a common master layout. I would like the logo, shared across the sites, to always go to the current websites frontpage, instead of going to "/" which results in going to the default website.

Best regards.

Jonas


Replies

 
Thomas Schroll
Reply

Hi Jonas

You can use 'DwAreaFirstPageID'

Regards Thomas

 
Jonas Mersholm
Reply

Hi Thomas.

Using the DwAreaFirstPageID returns nothing-

 

@GetValue("DwAreaFirstPageID");  is empty  <a href="/?ID=@GetValue("DwAreaFirstPageID")">Anchor</a> returns "/?ID="

and <!--@DwAreaFirstPageID--> simply returns <!--@DwAreaFirstPageID--> (Probably because i'm using razor templates.

 

Best regards.

Jonas

 
Thomas Schroll
Reply

Hi Jonas

You probably need to store it in a variable. You cannot use GetValue as an atrribute.

string firstPageID = GetString("DwAreaFirstPageID");
<a href="/Default.aspx?ID=@firstPageID" class="logo-image"></a>

works for me.

Regards Thomas

 
Mikkel Ricky
Reply

When using Razor, you should get the value directly from the Area rather than using a template tag:

@Pageview.Area.get_Value("AreaFirstPage")
Best regards,
Mikkel
 
Jonas Mersholm
Reply

Hi Mikkel, thanks for the answer.

I do see, that the tag returns the correct id, however, when i try to use it inside my anchor element, it simply inserts a "=" inside my href attribute.

 

<a href="/?ID=@Pageview.Area.get_Value("AreaFirstPage")">

<a href="/?ID=" =""="">

 
Mikkel Ricky
Reply

Dynamicweb uses HTML Agility Pack (HAP) for parsing layout templates and HAP gets confused when it sees double quotes inside attribute values. The easiest workaround is to quote the attribute value with single quotes rather than double quotes:

<a href='/?ID=@Pageview.Area.get_Value("AreaFirstPage")'>

Otherwise, you can use the trick that Thomas mentions, i.e. store the value in a variable (to get rid of the quotes inside quotes):

@{
var firstPageId = Pageview.Area.get_Value("AreaFirstPage");
}
<a href="/?ID=@firstPageId">

Best regards,
Mikkel

 

You must be logged in to post in the forum