Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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"
    ![CDATA[
                WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" xmlns:cewp="http://schemas.microsoft.com/WebPart/v2/ContentEditor"
                AssemblyMicrosoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c/Assembly
                TypeNameMicrosoft.SharePoint.WebPartPages.ContentEditorWebPart/TypeName
                TitleStructral Site Text/Title
                FrameTypeNone/FrameType
                cewp:Content
                  This is some content with a link. a href="http://mysite.com/mysubsite/"/a
                /cewp:Content
                /WebPart
                ]]
  /AllUsersWebPart
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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);
</script>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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