I have added a ContentEditorWebPart to an Element file in visual studio. I want to get the current site url and place it in the content block (between the cewp:Content tags).

How would i do this?

Please note i am in a sandboxed solution so this is the only way i can add a ContentEditorWebPart. How do i reference the current site url using the code below?

  AllUsersWebPart WebPartZoneID="FullPage1" WebPartOrder="0"
                WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:cewp="http://schemas.microsoft.com/WebPart/v2/ContentEditor"
                AssemblyMicrosoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c/Assembly
                TitleStructral Site Text/Title
                  This is some content with a link. a href="http://mysite.com/mysubsite/"/a

You could add some js script and use the _spPageContextInfo object.

 This is some content with a link. <a id="siteUrl">click here</a>   
<script language="JavaScript">
    document.getElementById('siteUrl').setAttribute('href', _spPageContextInfo.webServerRelativeUrl);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.